NetSocket data handler should report runtime failures to context exception handler - closes #3272

This commit is contained in:
Julien Viet
2020-02-02 21:52:41 +01:00
parent 7eb6f16b82
commit c2bb2e8a8b
2 changed files with 34 additions and 0 deletions

View File

@@ -88,6 +88,7 @@ public class NetSocketImpl extends ConnectionBase implements NetSocketInternal {
this.messageHandler = NULL_MSG_HANDLER;
pending = new InboundBuffer<>(context);
pending.drainHandler(v -> doResume());
pending.exceptionHandler(context::reportException);
pending.handler(obj -> {
if (obj == InboundBuffer.END_SENTINEL) {
Handler<Void> handler = endHandler();

View File

@@ -18,6 +18,7 @@ import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;
import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.*;
import io.vertx.core.Future;
import io.vertx.core.buffer.Buffer;
@@ -3765,4 +3766,36 @@ public class NetTest extends VertxTestBase {
assertEquals(8080, converted.port());
assertEquals("localhost", converted.host());
}
@Test
public void testNetSocketHandlerFailureReportedToContextExceptionHandler() throws Exception {
server.connectHandler(so -> {
Context ctx = Vertx.currentContext();
List<Throwable> reported = new ArrayList<>();
ctx.exceptionHandler(reported::add);
NullPointerException err1 = new NullPointerException();
so.handler(buff -> {
throw err1;
});
NullPointerException err2 = new NullPointerException();
so.endHandler(v ->{
throw err2;
});
NullPointerException err3 = new NullPointerException();
so.closeHandler(v1 -> {
ctx.runOnContext(v2 -> {
assertEquals(Arrays.asList(err1, err2, err3), reported);
testComplete();
});
throw err3;
});
});
startServer(testAddress);
client.connect(testAddress, onSuccess(so -> {
so.write("ping");
so.close();
}));
await();
}
}