-
Notifications
You must be signed in to change notification settings - Fork 975
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
fix: safety close in AsyncConnectionProvider #2935 #2960
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tishun could you take a look? thanks
CountDownLatch slowCreate = new CountDownLatch(1); | ||
CountDownLatch slowShutdown = new CountDownLatch(1); | ||
|
||
// create a provider with a slow connection creation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's means it will create an Sync
but hasn't completed yet, even when we need to close provider
}); | ||
|
||
// add slow shutdown connection first | ||
SlowCloseFuture slowCloseFuture = new SlowCloseFuture(slowShutdown); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use for blocking the iterating.
CompletableFuture<AsyncCloseable> createFuture = provider.getConnection("slowCreate"); | ||
|
||
// close the connection. | ||
CompletableFuture<Void> closeFuture = provider.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close the provider, the hashmap contains two elements, but only the slowShutdown
key Sync
will be add it to close futures
, because it has been created, but slowCreate
didn't(it will add it to futures after creation completed, this path will cause unsafety, which mean IndexOutOfBound or ConcurrentModificationException)
Motivation
ConcurrentHashMap didn't guarantee the iterator consistency with entries...
Make sure that:
mvn formatter:format
target. Don’t submit any formatting related changes.