GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Port: LocalChannel: complete connect() when the accepted channel dies before registration (#17656) by normanmaurer · Pull Request #17666 · netty/netty Conversation
Member
Motivation: If the server side
Related problems on the same path:
Modification:
Result:
The five new tests fail on 4.2 without the change and pass with it. I also ran a stress test (not included): client, server and accepted Known limitations:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…e registration (#17656) Motivation: If the server side `LocalChannel` of a connection is closed before it is registered, the client's `connect()` never completes (the local transport has no connect timeout). This happens when: - the `LocalServerChannel` is closed while the connection is still queued (auto-read off, or `server.close()` right after `connect()`), - the accepted channel cannot be registered (for example the child group is shut down). Related problems on the same path: - A connection that reaches the server after the server channel was closed is still accepted, and `connect()` succeeds against a closed server. - If the client closes while its connection is still queued, `client.close()` fails with `IllegalStateException: channel not registered to an event loop`. When the server accepts the connection later, the client is reopened (`isOpen()` is true again) and the accepted channel becomes active with a closed peer. The same `IllegalStateException` happens for `server.close(); client.close();` issued back to back while the connection is queued. Modification: - `LocalServerChannel`: close queued connections on close, and close connections that arrive after the channel was closed. - The client no longer touches an accepted channel that has not completed the connection. When the accepted channel is registered, it moves the client from `BOUND` to `CONNECTED` with a CAS. The client's `doClose()` uses `getAndSet(CLOSED)`, so exactly one side wins. If the client was closed first, the accepted channel closes itself on its own event loop. - `LocalChannel.tryClose(false)`: if a connect is still pending, the accepted channel was closed before the connection was established. Fail the connect with `ConnectException` (as when nothing is bound to the address) and close the client. A client that closes itself still fails its connect with `ClosedChannelException`. - `registered()` reads `peer` once instead of checking it and reading it again. - Add five tests to `LocalChannelTest`. Result: `connect()` fails with `ConnectException` instead of hanging when the server side goes away, a connection to an already closed server fails, and `client.close()` succeeds in the orderings above. The five new tests fail on 4.2 without the change and pass with it. `LocalChannelTest` (32 tests), the transport module (407 tests), the handler, handler-proxy, codec-haproxy and codec-http2 tests that use the local transport, and checkstyle pass. I also ran a stress test (not included): client, server and accepted channels on three event loops, and the client closes 0 to 100 µs after `connect()`. On 4.2, 20,000 iterations gave 499 `close()` failures with `IllegalStateException`, 2,024 clients open again after `close()`, and 1,523 accepted channels left open and active. With this change, 100,000 iterations with `-ea` had none of these, and every accepted channel was closed and deregistered. Known limitations: - A client that closes while its connection is queued is still accepted later: the child handler's `initChannel` runs and `channelRegistered` fires, then the accepted channel is closed without `channelActive`. - Queued connections that the server closes (on close, or when they arrive after close) were never registered. They are closed with `closeForcibly()`, so their `closeFuture` does not complete. Only code that overrides `newLocalChannel` can see these channels. - Not changed by this PR: if the client closes after the accepted channel completed the connection but before the client's event loop runs the connect success task, the client's pipeline gets `channelInactive` without `channelActive`. 4.2 does the same.
This comment has been minimized.Uh oh!
There was an error while loading. Please reload this page.
lltopk
pushed a commit
to lltopk/netty
that referenced
this pull request
… before registration (netty#17656) (netty#17666) Motivation: If the server side `LocalChannel` of a connection is closed before it is registered, the client's `connect()` never completes (the local transport has no connect timeout). This happens when: - the `LocalServerChannel` is closed while the connection is still queued (auto-read off, or `server.close()` right after `connect()`), - the accepted channel cannot be registered (for example the child group is shut down). Related problems on the same path: - A connection that reaches the server after the server channel was closed is still accepted, and `connect()` succeeds against a closed server. - If the client closes while its connection is still queued, `client.close()` fails with `IllegalStateException: channel not registered to an event loop`. When the server accepts the connection later, the client is reopened (`isOpen()` is true again) and the accepted channel becomes active with a closed peer. The same `IllegalStateException` happens for `server.close(); client.close();` issued back to back while the connection is queued. Modification: - `LocalServerChannel`: close queued connections on close, and close connections that arrive after the channel was closed. - The client no longer touches an accepted channel that has not completed the connection. When the accepted channel is registered, it moves the client from `BOUND` to `CONNECTED` with a CAS. The client's `doClose()` uses `getAndSet(CLOSED)`, so exactly one side wins. If the client was closed first, the accepted channel closes itself on its own event loop. - `LocalChannel.tryClose(false)`: if a connect is still pending, the accepted channel was closed before the connection was established. Fail the connect with `ConnectException` (as when nothing is bound to the address) and close the client. A client that closes itself still fails its connect with `ClosedChannelException`. - `registered()` reads `peer` once instead of checking it and reading it again. - Add five tests to `LocalChannelTest`. Result: `connect()` fails with `ConnectException` instead of hanging when the server side goes away, a connection to an already closed server fails, and `client.close()` succeeds in the orderings above. The five new tests fail on 4.2 without the change and pass with it. `LocalChannelTest` (32 tests), the transport module (407 tests), the handler, handler-proxy, codec-haproxy and codec-http2 tests that use the local transport, and checkstyle pass. I also ran a stress test (not included): client, server and accepted channels on three event loops, and the client closes 0 to 100 µs after `connect()`. On 4.2, 20,000 iterations gave 499 `close()` failures with `IllegalStateException`, 2,024 clients open again after `close()`, and 1,523 accepted channels left open and active. With this change, 100,000 iterations with `-ea` had none of these, and every accepted channel was closed and deregistered. Known limitations: - A client that closes while its connection is queued is still accepted later: the child handler's `initChannel` runs and `channelRegistered` fires, then the accepted channel is closed without `channelActive`. - Queued connections that the server closes (on close, or when they arrive after close) were never registered. They are closed with `closeForcibly()`, so their `closeFuture` does not complete. Only code that overrides `newLocalChannel` can see these channels. - Not changed by this PR: if the client closes after the accepted channel completed the connection but before the client's event loop runs the connect success task, the client's pipeline gets `channelInactive` without `channelActive`. 4.2 does the same. --------- Co-authored-by: allthingssecurity <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |