-
Notifications
You must be signed in to change notification settings - Fork 5.5k
syscall: refactor address APIs for deeper errno latching #3897
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
Changes from 5 commits
4b581b3
6c65b13
36c81e5
bb2841e
7e05d55
dc0c613
42d0771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,10 +551,10 @@ ClientConnectionImpl::ClientConnectionImpl( | |
| } | ||
|
|
||
| if (source_address != nullptr) { | ||
| const int rc = source_address->bind(fd()); | ||
| if (rc < 0) { | ||
| Api::SysCallResult result = source_address->bind(fd()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: result here and below can be const.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 42d0771. |
||
| if (result.rc_ < 0) { | ||
| ENVOY_LOG_MISC(debug, "Bind failure. Failed to bind to {}: {}", source_address->asString(), | ||
| strerror(errno)); | ||
| strerror(result.errno_)); | ||
| bind_error_ = true; | ||
| // Set a special error state to ensure asynchronous close to give the owner of the | ||
| // ConnectionImpl a chance to add callbacks and detect the "disconnect". | ||
|
|
@@ -568,19 +568,19 @@ ClientConnectionImpl::ClientConnectionImpl( | |
|
|
||
| void ClientConnectionImpl::connect() { | ||
| ENVOY_CONN_LOG(debug, "connecting to {}", *this, socket_->remoteAddress()->asString()); | ||
| const int rc = socket_->remoteAddress()->connect(fd()); | ||
| if (rc == 0) { | ||
| Api::SysCallResult result = socket_->remoteAddress()->connect(fd()); | ||
| if (result.rc_ == 0) { | ||
| // write will become ready. | ||
| ASSERT(connecting_); | ||
| } else { | ||
| ASSERT(rc == -1); | ||
| if (errno == EINPROGRESS) { | ||
| ASSERT(result.rc_ == -1); | ||
| if (result.errno_ == EINPROGRESS) { | ||
| ASSERT(connecting_); | ||
| ENVOY_CONN_LOG(debug, "connection in progress", *this); | ||
| } else { | ||
| immediate_error_event_ = ConnectionEvent::RemoteClose; | ||
| connecting_ = false; | ||
| ENVOY_CONN_LOG(debug, "immediate connection error: {}", *this, errno); | ||
| ENVOY_CONN_LOG(debug, "immediate connection error: {}", *this, result.errno_); | ||
|
|
||
| // Trigger a write event. This is needed on OSX and seems harmless on Linux. | ||
| file_event_->activate(Event::FileReadyType::Write); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,10 @@ namespace Common { | |
| namespace Statsd { | ||
|
|
||
| Writer::Writer(Network::Address::InstanceConstSharedPtr address) { | ||
| fd_ = address->socket(Network::Address::SocketType::Datagram); | ||
| fd_ = address->socket(Network::Address::SocketType::Datagram).rc_; | ||
| ASSERT(fd_ != -1); | ||
|
|
||
| int rc = address->connect(fd_); | ||
| const int rc = address->connect(fd_).rc_; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to keep the SysCallResult instead of an int, so that if the assert fires in a test it's easier in a debugger to see the value of errno.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 42d0771. |
||
| ASSERT(rc != -1); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the
__APPLE__case, I think that fcntl could be resetting errno, so you need to latch it earlier.On the other hand, there's already a RELEASE_ASSERT that an error did not occur (fd != -1). So should this function even return errno?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggreenway good catch! What do you suggest? Should we still keep the function return type as
Api::SysCallResultfor consistency, and to provide a way for future error handling?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say leave this function as returning an int, and make sure the docs mention that this will never fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in dc0c613.