Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4dbf11c

Browse files
committed
Fix semaphore not being released on Throwable, seeAsyncHttpClient#1314
Motivation:Fix forAsyncHttpClient#1314 introduced a regression where the Semaphore leaks and isnot released on Throwable.Modification:Release Semaphore when called handler method is onThrowable too, notonly onComplete.ResultNo more Semaphore leak
1 parentfd907c0 commit4dbf11c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

‎client/src/main/java/org/asynchttpclient/filter/ReleasePermitOnComplete.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
importorg.asynchttpclient.AsyncHandler;
1212

1313
/**
14-
* Wrapper for {@link AsyncHandler}s to release a permit on {@link AsyncHandler#onCompleted()}.
15-
* This is done via a dynamic proxy to preserve all interfaces of the wrapped handler.
14+
* Wrapper for {@link AsyncHandler}s to release a permit on {@link AsyncHandler#onCompleted()}. This is done via a dynamic proxy to preserve all interfaces of the wrapped handler.
1615
*/
1716
publicclassReleasePermitOnComplete {
1817

1918
/**
2019
* Wrap handler to release the permit of the semaphore on {@link AsyncHandler#onCompleted()}.
20+
*
21+
* @param handler the handler to be wrapped
22+
* @param available the Semaphore to be released when the wrapped handler is completed
23+
* @return the wrapped handler
2124
*/
2225
@SuppressWarnings("unchecked")
2326
publicstatic <T>AsyncHandler<T>wrap(finalAsyncHandler<T>handler,finalSemaphoreavailable) {
@@ -31,8 +34,11 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
3134
try {
3235
returnmethod.invoke(handler,args);
3336
}finally {
34-
if ("onCompleted".equals(method.getName())) {
37+
switch (method.getName()) {
38+
case"onCompleted":
39+
case"onThrowable":
3540
available.release();
41+
default:
3642
}
3743
}
3844
}
@@ -41,6 +47,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
4147

4248
/**
4349
* Extract all interfaces of a class.
50+
* @param handlerClass the handler class
51+
* @return all interfaces implemented by this class
4452
*/
4553
staticClass<?>[]allInterfaces(Class<?>handlerClass) {
4654
Set<Class<?>>allInterfaces =newHashSet<>();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp