Repository navigation
net: posix: make socket shutdown abort a retried connect - #329
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The test helper can exhaust a common 1,024-descriptor limit before exercising shutdown, so it must explicitly skip on descriptor exhaustion or avoid reserving the full socket range.
1 open issue
What changed in this PR
This PR makes POSIX socket shutdown persist across connection retries, preventing a new attempt from continuing after the caller has shut down the socket.
Changes:
- Track shutdown state and reject subsequent connection attempts with
ECONNABORTED. - Add a regression test that forces local-port collisions and checks that shutdown resolves the pending connection.
| File | Description |
|---|---|
tests/unit/connect_test.cc |
Adds fixtures and a shutdown-across-port-retry regression test. |
src/net/posix-stack.cc |
Records shutdown state and checks it before creating connection sockets. |
Review effort: Balanced
|
upstream: scylladb#3853 |
bcb05dd to
ee44a2f
Compare
|
What's the actual flow in the code? Is it something like: ? |
|
posix_socket_impl::shutdown() only shut down the file descriptor the socket held at that moment. find_port_and_connect() retries on a new one after a local port collision, so a shutdown that landed between two attempts did not stop the retry. Instead, it went on connecting as if no shutdown had been requested. Remember a shutdown issued while connect() is in progress, and fail with ECONNABORTED instead of retrying. connect() clears it when it starts, so a shutdown() before connect() is still a no-op.
ee44a2f to
0bde9f5
Compare
| break; | ||
| } catch (std::system_error& err) { | ||
| if (port != requested_port && (err.code().value() == EADDRINUSE || err.code().value() == EADDRNOTAVAIL)) { | ||
| if (std::exchange(_shutdown, false)) { |
There was a problem hiding this comment.
What's the thinking for the exchange? To reuse a shut down connection somehow?
There was a problem hiding this comment.
Yeah, Avi pointed out on the upstream PR that shutdown(2) doesn't prevent reuse of the socket, just a shutdown of the current connection.
You can check the conversation out on the upstream PR
|
Approved & merged by Avi upstream |
|
auto merge is on |

posix_socket_impl::shutdown() only shut down the file descriptor the socket held at that moment. find_port_and_connect() retries on a new one after a local port collision, so a shutdown that landed between two attempts did not stop the retry. Instead, it went on connecting as if no shutdown had been requested.
Remember a shutdown issued while connect() is in progress, and fail with ECONNABORTED instead of retrying. connect() clears it when it starts, so a shutdown() before connect() is still a no-op.
Found by investigating reported LSan leaks in https://redpandadata.atlassian.net/browse/CORE-18210.