Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[network] handle onWriteReady socket failure #15137

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/common/network/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ void ConnectionImpl::onWriteReady() {
int error;
socklen_t error_size = sizeof(error);
RELEASE_ASSERT(socket_->getSocketOption(SOL_SOCKET, SO_ERROR, &error, &error_size).rc_ == 0,
asraa marked this conversation as resolved.
Show resolved Hide resolved
"");
fmt::format("Failed to connect: {}", error));

if (error == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined behavior: error is not inialized if result.rc_ != 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I was under the impression error would be set, but it's actually two separate things. I'll handle getSocketOption return error with an ENVOY_BUG (since this is unexpected) and close socket, and error != 0 additionally with close socket.

Checking my understanding. getSocketOption can fail for e.g. if the fd is invalid, or we don't have enough resources. If we succeed, the socket may still have a pending error returned with error that happened between socket calls. Maybe like connection refused?

ENVOY_CONN_LOG(debug, "connected", *this);
Expand Down