-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#1412 Wait for async close tasks before close completes #1435
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.
Thanks a lot!
Could you please have a look at my question?
|
||
//see https://github.com/netty/netty/issues/2084#issuecomment-44822314 | ||
try { | ||
ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS); |
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.
Shouldn't the await activity be aligned with AsyncHttpClientConfig#getShutdownTimeout
or AsyncHttpClientConfig#getShutdownQuietPeriod
instead of being hard coded?
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.
Yes, I guess aligning it with AsyncHttpClientConfig#getShutdownTimeout
makes absolutely sense. The quietPeriod seems to have different meaning and I guess it is inappropriate at this place.
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.
👍
|
||
//see https://github.com/netty/netty/issues/2084#issuecomment-44822314 | ||
try { | ||
GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS); |
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.
Same here
// Ignore | ||
} | ||
|
||
closeLatch.countDown(); |
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.
In finally block?
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.
Yes could be done to cover the corner cases.
@@ -310,6 +324,13 @@ public void close() { | |||
.addListener(future -> doClose()); | |||
} else | |||
doClose(); | |||
|
|||
try { | |||
closeLatch.await(); |
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.
No timeout for this await?
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.
yes, timeout could be reused!
@@ -23,7 +23,7 @@ public AsyncHttpClientState(AtomicBoolean closed) { | |||
this.closed = closed; | |||
} | |||
|
|||
public boolean isClosed() { | |||
public boolean isClosedOrClosingIsTriggered() { | |||
return closed.get(); |
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.
I guess it's best to rename closed
into closeTriggered
.
@@ -597,7 +597,7 @@ public void replayRequest(final NettyResponseFuture<?> future, FilterContext fc, | |||
} | |||
|
|||
public boolean isClosed() { |
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.
Rename method too.
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.
Done and attached another commit to the pull request!
I'm just wondering... Will this interfere with other parts of an application that also use Netty? So let's say I close an AHC instance but have some other Netty-based component, e.g. a server component - or just another AHC instance - that is still in use. To me, it sounds like those global helper methods would then just run into a timeout. |
Yeah, actually I think @twz123 is right and this would also break for people who spawn and shutdown AHC instances at runtime without stopping the application :( |
@twz123 thanks for the check but I can't see any interference to other instances of AHC or netty. If there is still activity on the threads the The If we could not clarify this today we have to discuss this another time because I'm out of office for four weeks now (starting tomorrow). Sorry for this inconvenience. |
Hey @MiErnst,
Okay, that's true. Maybe I should have written in passive voice "is affected by other parts of the app that use Netty" instead of "interferes with". My caveat is exactly what you wrote:
So the blocking behavior of From my point of view, there are several possibilities now:
|
} | ||
|
||
public boolean isClosed() { | ||
return closed.get(); | ||
public boolean isCloseTriggered() { |
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.
What's wrong with the old name?
try { | ||
ThreadDeathWatcher.awaitInactivity(config.getShutdownTimeout(), TimeUnit.MILLISECONDS); | ||
} catch(InterruptedException t) { | ||
// Ignore |
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.
Re-assert interrupted status
try { | ||
GlobalEventExecutor.INSTANCE.awaitInactivity(config.getShutdownTimeout(), TimeUnit.MILLISECONDS); | ||
} catch(InterruptedException t) { | ||
// Ignore |
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.
Re-assert interrupted status
try { | ||
closeLatch.await(config.getShutdownTimeout(), TimeUnit.MILLISECONDS); | ||
} catch (InterruptedException e) { | ||
// Ignore |
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.
Re-assert interrupted status
Hi guys, is there a plan to release these commits? |
@zhan-ge There was changes request,so won't be any soon.and AHC has its own release cycle. |
Frankly, I'm not fond of this implementation.
So having a mechanism based on this Why not keeping track of flying requests? Like having an |
Hey together, sorry for the circumstances that I wasn’t able to work on this pull request. @twz123
As you can see in the implementation I changed the return type of the ChannelManager’s close method. Although this method is public, the instance of the ChannelManager seems only to managed by the DefaultAsyncHttpClient and is not returned by any public method of this client, so I think this internal API change should not be a problem. The current close method also waits for the ChannelManager to complete successfully. If the eventLoopGroup is going to shutdown gracefully, the close will wait till this method completes but I think this is OK because it’s a resource created by the AHC. To prevent the amount of TimeoutExceptions in the travis build, the system property org.asynchttpclient.shutdownTimeout in the surefire plugin configuration has to be increased to 1500 because the gracefull shutdown needs at least 1.2 seconds to complete. I don’t know if this affects the travis build time to much so it is currently not part of the push request. I don’t think the currently failed test is related to this implementation. Can’t see what the cause is. @slandelle |
9334a56
to
391b4d8
Compare
Can you guys just change it to this and be done with it, I think by the time they are closing the pool waiting sync vs async does not matter that much:
|
6ea11f4
to
f8fab66
Compare
#1412 Implemented a count down latch and called some API methods to close resources of netty.