-
Notifications
You must be signed in to change notification settings - Fork 1.6k
NullPointerException #1769
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
Comments
Hey @aqingsao - new maintainer here, still learning the ropes. Can you show the exact code you used + mention some specs? Might help the investigation. |
Hi TomGranot, Some codes are pasted in below but I don't think it provides any clues.
|
I think I have the same issue. We have a unit test where we simulate a "connection reset by peer" which worked fine on async-http-client version 2.12.1
For what I've seen in
and |
Some extra information. We could reproduce it at our side with the following unit test which uses WireMock (Kotlin code):
I took a quick look in the source code, but couldn't directly find a way to create a test case simulating a "connection reset by peer" in this repo. |
Hi, I extracted resetting server logic from the tests I have. Here's simple test public class AsyncHttpClientTest {
private String resettingServerAddress;
@Before
public void setUp() {
resettingServerAddress = createResettingServer();
}
@Test
public void testAsyncHttpClient() throws ExecutionException, InterruptedException {
try {
new DefaultAsyncHttpClient().executeRequest(new org.asynchttpclient.RequestBuilder("GET").setUrl(resettingServerAddress)).get();
} catch (ExecutionException e) {
var ex = e.getCause();
assertTrue(ex instanceof SocketException);
assertTrue(ex.getMessage().equalsIgnoreCase("connection reset"));
}
}
private static String createResettingServer() {
return createServer(sock -> {
try (Socket socket = sock) {
socket.setSoLinger(true, 0);
var inputStream = socket.getInputStream();
//to not eliminate read
OutputStream.nullOutputStream().write(startRead(inputStream));
}
});
}
private static String createServer(MoreFunctionalInterfaces.FailableConsumer<Socket, Exception> handler) {
Exchanger<Integer> portHolder = new Exchanger<>();
var t = new Thread(() -> {
try (ServerSocket ss = new ServerSocket(0)) {
portHolder.exchange(ss.getLocalPort());
while (true) {
handler.accept(ss.accept());
}
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
throw new RuntimeException(e);
}
});
t.setDaemon(true);
t.start();
return tryGetAddress(portHolder);
}
private static String tryGetAddress(Exchanger<Integer> portHolder) {
try {
return "http://localhost:" + portHolder.exchange(0);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
private static byte[] startRead(InputStream inputStream) throws IOException {
byte[] buffer = new byte[4];
int length = inputStream.read(buffer);
return Arrays.copyOf(buffer, length);
}
} |
That certainly helps @dzharikhin! |
Thnx for merging @TomGranot, this issue can be closed now. FWIW, when using the new version of async-http-client (2.12.3) the issue is solved in our project. |
@rachidbm Excellent, closing this as well. |
I've been using async-http-client for a long time, it works fine in many cases even at a high QPS of 100K.
But recently some errors happen when calls to a specific api(nothing special, just a POST http with Content-Type: multipart/form-data), lots of exceptions are thrown at a low QPS of 800, and below is the stack trace:
`java.lang.NullPointerException: null
at org.asynchttpclient.netty.channel.Channels.getAttribute(Channels.java:31) ~[async-http-client-2.12.2.jar!/:na]
at org.asynchttpclient.netty.request.NettyRequestSender.abort(NettyRequestSender.java:467) ~[async-http-client-2.12.2.jar!/:na]
at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.exceptionCaught(AsyncHttpClientHandler.java:201) ~[async-http-client-2.12.2.jar!/:na]
at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:264) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.handler.stream.ChunkedWriteHandler.channelInactive(ChunkedWriteHandler.java:138) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:81) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.handler.codec.http.HttpContentDecoder.channelInactive(HttpContentDecoder.java:235) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelInactive(CombinedChannelDuplexHandler.java:418) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java:389) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:354) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.handler.codec.http.HttpClientCodec$Decoder.channelInactive(HttpClientCodec.java:311) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.CombinedChannelDuplexHandler.channelInactive(CombinedChannelDuplexHandler.java:221) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:241) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java:1405) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:262) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:248) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:901) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.AbstractChannel$AbstractUnsafe$8.run(AbstractChannel.java:819) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-all-4.1.55.Final.jar!/:4.1.55.Final]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_102]
Any idea of what can I do?
The text was updated successfully, but these errors were encountered: