You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "AdzerKI (via GitHub)" <gi...@apache.org> on 2026/10/02 02:30:54 UTC
[PR] Complete I/O reactor termination when the selector has been closed by another thread [httpcomponents-core]
AdzerKI opened a new pull request, #718:
URL: https://github.com/apache/httpcomponents-core/pull/718
We hit this with HttpClient 5 talking to a TLS 1.3 server that does not answer close_notify (JDK default, `jdk.tls.acknowledgeCloseNotify=false`). `CloseableHttpAsyncClient#close()` waits for the graceful shutdown, gives up after 5 seconds, and `MultiCoreIOReactor` then closes each `SingleCoreIOReactor` with `CloseMode.IMMEDIATE` from the calling thread. That closes the selector while the I/O dispatch thread is still running. Its `doTerminate` calls `closeOpenChannels`, `selector.keys()` throws, and the default `LoggingExceptionCallback` logs an ERROR on every client shutdown:
```
java.nio.channels.ClosedSelectorException
at java.base/sun.nio.ch.SelectorImpl.ensureOpen(Unknown Source)
at java.base/sun.nio.ch.SelectorImpl.keys(Unknown Source)
at org.apache.hc.core5.reactor.SingleCoreIOReactor.closeOpenChannels(SingleCoreIOReactor.java:418)
at org.apache.hc.core5.reactor.SingleCoreIOReactor.doTerminate(SingleCoreIOReactor.java:117)
at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:99)
at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
```
The exception also skips `processClosedSessions`, so the handlers of sessions closed by `close(CloseMode)` never get `disconnected`.
By then `close(CloseMode)` has already closed the registered channels, so `closeOpenChannels` now just returns when the selector is closed and termination goes on. `doExecute` already ignores `ClosedSelectorException` for the same reason.
Test: `TestSingleCoreIOReactor#terminatesWhenSelectorClosedByAnotherThread` holds the dispatch thread in `connected`, closes the reactor from the test thread, then lets the dispatch thread go. It expects no reported exception and a `disconnected` call. Fails on master with `ClosedSelectorException`, passes with the fix; `httpcore5` builds with all tests.
The same code is on 5.4.x (the stack trace above is from 5.4.3).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] Complete I/O reactor termination when the selector has been closed by another thread [httpcomponents-core]
Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c commented on PR #718:
URL: https://github.com/apache/httpcomponents-core/pull/718#issuecomment-5948414545
@AdzerKI Cherry-picked to `5.4.x`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org
Re: [PR] Complete I/O reactor termination when the selector has been closed by another thread [httpcomponents-core]
Posted by "ok2c (via GitHub)" <gi...@apache.org>.
ok2c merged PR #718:
URL: https://github.com/apache/httpcomponents-core/pull/718
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org