You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
jersey-netty-connector Intermittent Stuck eventLoop/ExecuterService threads if Request failed in writeEntity(executed in pool threads) under load
#5837
Open
sumitaneja opened this issue
Jan 15, 2025
· 1 comment
NettyConnector doesn't blcoks eventLoops threads and eventually ExecutorServiceThreads under stress if writeEntity(executed in pool threads) fails/throw error for some reason.
We noticed this happening in two cases
Malformed request (say content type is multipart and no body part is present). Request Errors out with illegal argument exception.
We are sending large binary payload and target system returns 413. Occasionally there are BuffereOverflow and Stream Closed Exceptions too.
Issue identified in below code with NettyConnector
if (entityWriter.getType() == NettyEntityWriter.Type.DELAYED) {
contentLengthSet.await();
}
entityWriter.flush();
Our analysis shows this to be timing issue in case of error. I.e Line 509 [entityWriter.flush();] executes before 488 [responseDone.completeExceptionally(e);]. (issue can be recreated without stress by putting a simple sleep before 488)
NettyConnector doesn't blcoks eventLoops threads and eventually ExecutorServiceThreads under stress if writeEntity(executed in pool threads) fails/throw error for some reason.
We noticed this happening in two cases
Issue identified in below code with NettyConnector
jersey/connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/NettyConnector.java
Lines 473 to 509 in d9658aa
Our analysis shows this to be timing issue in case of error. I.e Line 509 [entityWriter.flush();] executes before 488 [responseDone.completeExceptionally(e);]. (issue can be recreated without stress by putting a simple sleep before 488)
Issue:
Line 509 starts task in nioEventloopGroup which tries to read chunks. This goes on till Channel is writable and pendingMessage is Chunked Input.
See https://github.com/netty/netty/blob/4.1/handler/src/main/java/io/netty/handler/stream/ChunkedWriteHandler.java#L225-269
Once it goes in loop to read chunks, exception in doesnt signal this loop to break.
Possible fix in Netty Connector
close chunked input in NettyConnector on exception at line 488
Sample code fix
}catch (Throwable e){
if(entityWriter.getChunkedInput()!=null){
try {
System.out.println(" CLOSING CHUNKED");
entityWriter.getChunkedInput().close();
} catch (Exception ex) {
System.out.println("ERROR CLOSING CHUNKED");
}
}
responseDone.completeExceptionally(e);
}
The text was updated successfully, but these errors were encountered: