Commit b8386a1
Fix concurrency issue from modifying the selectedKeysSet
This bug may have been a regression introduced in optimizing the key removal: a7c3106
To reproduce refer to poc:
https://github.com/kevink-sq/jetty-concurrency-issue-poc
To verify fix, refer to poc branch (same as these changes):
https://github.com/kevink-sq/jetty-concurrency-issue-poc/tree/kevink/attempted-junixsocket-fix-2
Jetty's [ManagedSelector](https://github.com/jetty/jetty.project/blob/7a7d69a69f4f51772e20813332291189a24e91b1/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java#L655)
iterates through the selectedKeysSet and when separate processes cancel
the AFSelectorKey, the iterator throws a `ConcurrentModificationException`.
Fix is to introduce `cancelledKeysSet` to defer removal of cancelled
keys until the select process. Use of the cancelled sets are referenced
from java.nio.channels.spi's `AbstractSelector` and `AbstractSelectionKey`.
Ideally we'd have `AFSelectionKey` extend from `AbstractSelectionKey` to
leverage the base class's internal cancelled set
but`AbstractSelectionKey` defines its own `isValid` and `cancel` and
cannot override the base's final methods.
Also added an atomic check to `AFSelectionKey#cancel` to prevent "Too
many open files" socket exception.1 parent 43cbb88 commit b8386a1
2 files changed
Lines changed: 23 additions & 2 deletions
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
115 | 117 | | |
116 | 118 | | |
117 | 119 | | |
| |||
299 | 301 | | |
300 | 302 | | |
301 | 303 | | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
302 | 321 | | |
303 | 322 | | |
304 | 323 | | |
| |||
0 commit comments