Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ConcurrentPool concurrency #12289

Closed
sbordet opened this issue Sep 18, 2024 · 0 comments · Fixed by #12290
Closed

Improve ConcurrentPool concurrency #12289

sbordet opened this issue Sep 18, 2024 · 0 comments · Fixed by #12290
Assignees
Labels
Bug For general bugs on Jetty side Sponsored This issue affects a user with a commercial support agreement

Comments

@sbordet
Copy link
Contributor

sbordet commented Sep 18, 2024

Jetty version(s)
12

Description

java.lang.ArrayIndexOutOfBoundsException: Index 249 out of bounds for length 249
        at java.base/java.util.concurrent.CopyOnWriteArrayList.elementAt(CopyOnWriteArrayList.java:390)
        at java.base/java.util.concurrent.CopyOnWriteArrayList.get(CopyOnWriteArrayList.java:403)
        at org.eclipse.jetty.util.ConcurrentPool.sweep(ConcurrentPool.java:200)
        at org.eclipse.jetty.util.ConcurrentPool.reserve(ConcurrentPool.java:178)
        at org.eclipse.jetty.client.AbstractConnectionPool.tryCreate(AbstractConnectionPool.java:281)
        at org.eclipse.jetty.client.AbstractConnectionPool.acquire(AbstractConnectionPool.java:235)
        at org.eclipse.jetty.client.transport.HttpDestination.process(HttpDestination.java:372)
        at org.eclipse.jetty.client.transport.HttpDestination.send(HttpDestination.java:358)
        at org.eclipse.jetty.client.transport.HttpDestination.succeeded(HttpDestination.java:291)
        at org.eclipse.jetty.client.AbstractConnectionPool.proceed(AbstractConnectionPool.java:315)
        at org.eclipse.jetty.client.AbstractConnectionPool$FutureConnection.succeeded(AbstractConnectionPool.java:615)
        at org.eclipse.jetty.client.AbstractConnectionPool$FutureConnection.succeeded(AbstractConnectionPool.java:593)
        at org.eclipse.jetty.util.Promise$Wrapper.succeeded(Promise.java:195)
        at org.eclipse.jetty.client.transport.internal.HttpConnectionOverHTTP.onOpen(HttpConnectionOverHTTP.java:209)
        at org.eclipse.jetty.io.SelectorManager.connectionOpened(SelectorManager.java:325)
        at org.eclipse.jetty.io.ClientConnector$ClientSelectorManager.connectionOpened(ClientConnector.java:616)
        at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:401)
        at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:1056)
        at org.eclipse.jetty.util.thread.MonitoredQueuedThreadPool$1.run(MonitoredQueuedThreadPool.java:73)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:979)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1209)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1164)
        at java.base/java.lang.Thread.run(Thread.java:1570)
@sbordet sbordet added the Bug For general bugs on Jetty side label Sep 18, 2024
@sbordet sbordet self-assigned this Sep 18, 2024
@sbordet sbordet added the Sponsored This issue affects a user with a commercial support agreement label Sep 18, 2024
@sbordet sbordet changed the title Improve ConcurrentPool reserve()/remove() concurrency Improve ConcurrentPool concurrency Sep 18, 2024
sbordet added a commit that referenced this issue Sep 18, 2024
A call to `sweep()`, although protected by the lock for concurrent calls to `reserve()`, may be concurrent with `remove(Entry)`.

`remove(Entry)` in turn calls `entries.remove(Object)`, so that the concurrent iteration in `sweep()` over `entries` fails with an `ArrayIndexOutOfBoundsException`.

Now using the bulk `entries.removeIf(Predicate)` method in `sweep()`, so that sweeping is atomic with respect to `entries.remove(Object)`.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet linked a pull request Sep 18, 2024 that will close this issue
sbordet added a commit that referenced this issue Sep 20, 2024
A call to `sweep()`, although protected by the lock for concurrent calls to `reserve()`, may be concurrent with `remove(Entry)`.

`remove(Entry)` in turn calls `entries.remove(Object)`, so that the concurrent iteration in `sweep()` over `entries` fails with an `ArrayIndexOutOfBoundsException`.

Now using the bulk `entries.removeIf(Predicate)` method in `sweep()`, so that sweeping is atomic with respect to `entries.remove(Object)`.

Fixed other occurrences of manual iteration over CopyOnWriteArrayList that may be concurrent with removals.

Signed-off-by: Simone Bordet <[email protected]>
gregw added a commit that referenced this issue Sep 23, 2024
…l concurrency. (#12290)"

This reverts/modified parts of commit 115ee1c.
gregw added a commit that referenced this issue Sep 23, 2024
…l concurrency. (#12290)"

This reverts/modified parts of commit 115ee1c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side Sponsored This issue affects a user with a commercial support agreement
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

1 participant