Fix file descriptor leak under high concurrency#144
Merged
kohlschuetter merged 1 commit intokohlschutter:mainfrom Nov 6, 2023
Merged
Fix file descriptor leak under high concurrency#144kohlschuetter merged 1 commit intokohlschutter:mainfrom
kohlschuetter merged 1 commit intokohlschutter:mainfrom
Conversation
With our PoC at https://github.com/kevink-sq/jetty-concurrency-issue-poc/tree/575469b3453e7b09d9d60f6460cdab8117b8e773, we noticed that there is unbounded growth of file descriptors when running our simple load test: ```bash seq 1 15000 | xargs -P1500 -I{} curl --unix-socket ./junix-ingress.sock http://localhost/process ``` Leading to timeouts from curl and timeout exceptions in jetty: ``` java.util.concurrent.TimeoutException: Idle timeout expired: 32422/30000 ms at org.eclipse.jetty.io.IdleTimeout.checkIdleTimeout(IdleTimeout.java:170) at org.eclipse.jetty.io.IdleTimeout.idleCheck(IdleTimeout.java:112) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) ``` This patch fixes the issue by ensuring that keys with the `OP_INVALID` bit are still tracked in the selected key set and cancelled accordingly Changes: * Add invalid keys to `selectedKeysSet` in `setOpsReady` and mark as cancelled, ensuring that the fd is cleaned up timely * Switch from `cancelNoRemove` to `cancel` now that the registered keys are modified separately in the select implementation * Prefer `!key.isValid()` over `key.hasOpInvalid()` since the former is a superset of the latter * In `implCloseSelector`, cancel the keys before clearing `keysRegistered` since `keys()` is backed by `keysRegistered` * Store cancelled keys in a deque instead of a hash set, which should be a little more efficient * Remove dead code
|
without this PR, on the poc you can verify excessive file descriptions are being creating in |
kevink-sq
added a commit
to kevink-sq/jetty-concurrency-issue-poc
that referenced
this pull request
Oct 31, 2023
kevink-sq
added a commit
to kevink-sq/jetty-concurrency-issue-poc
that referenced
this pull request
Nov 3, 2023
kevink-sq
added a commit
to kevink-sq/jetty-concurrency-issue-poc
that referenced
this pull request
Nov 6, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
With our PoC at
https://github.com/kevink-sq/jetty-concurrency-issue-poc/tree/575469b3453e7b09d9d60f6460cdab8117b8e773, we noticed that there is unbounded growth of file descriptors when running our simple load test:
seq 1 15000 | xargs -P1500 -I{} curl --unix-socket ./junix-ingress.sock http://localhost/processLeading to timeouts from curl and timeout exceptions in jetty:
This patch fixes the issue by ensuring that keys with the
OP_INVALIDbit are still tracked in the selected key set and cancelled accordinglyChanges:
selectedKeysSetinsetOpsReadyand mark as cancelled, ensuring that the fd is cleaned up timelycancelNoRemovetocancelnow that the registered keys are modified separately in the select implementation!key.isValid()overkey.hasOpInvalid()since the former is a superset of the latterimplCloseSelector, cancel the keys before clearingkeysRegisteredsincekeys()is backed bykeysRegistered