Skip to content
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

fix #1165 Change the state after notifying that the connection is acquired successfully. #1198

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/reactor/netty/channel/ChannelOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public ChannelOperations<INBOUND, OUTBOUND> withConnection(Consumer<? super Conn

@Override
public void dispose() {
if (log.isTraceEnabled()) {
log.trace(format(channel(), "Disposing ChannelOperation from a channel"),
new Exception("ChannelOperation dispose stack"));
}
OUTBOUND_CLOSE.set(this, Operators.cancelledSubscription());
if (!inbound.isDisposed()) {
inbound.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ public void onUncaughtException(Connection connection, Throwable error) {
@Override
public void onStateChange(Connection connection, State newState) {
if (newState == State.CONFIGURED) {
// First send a notification that the connection is ready and then change the state
// In case a cancellation was received, ChannelOperations will be disposed
// and there will be no subscription to the I/O handler at all.
// https://github.com/reactor/reactor-netty/issues/1165
simonbasle marked this conversation as resolved.
Show resolved Hide resolved
sink.success(connection);
}
obs.onStateChange(connection, newState);
Expand Down Expand Up @@ -600,8 +604,12 @@ else if (current == null) {
ChannelOperations<?, ?> ops = opsFactory.create(pooledConnection, pooledConnection, null);
if (ops != null) {
ops.bind();
obs.onStateChange(ops, State.CONFIGURED);
// First send a notification that the connection is ready and then change the state
// In case a cancellation was received, ChannelOperations will be disposed
// and there will be no subscription to the I/O handler at all.
// https://github.com/reactor/reactor-netty/issues/1165
sink.success(ops);
obs.onStateChange(ops, State.CONFIGURED);
}
else {
//already configured, just forward the connection
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/reactor/netty/http/server/HttpServerTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ public void testIssue630() {
}

@Test
@SuppressWarnings("FutureReturnValueIgnored")
public void testExpectErrorWhenConnectionClosed() throws Exception {
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext serverCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
Expand All @@ -1142,7 +1143,8 @@ public void testExpectErrorWhenConnectionClosed() throws Exception {
.port(0)
.secure(spec -> spec.sslContext(serverCtx))
.handle((req, res) -> {
res.withConnection(DisposableChannel::dispose);
// "FutureReturnValueIgnored" is suppressed deliberately
res.withConnection(conn -> conn.channel().close());
return res.sendString(Flux.just("OK").hide())
.then()
.doOnError(t -> {
Expand Down