Skip to content

Commit 0243aab

Browse files
committed
Preserve interrupt flag in H2 pool close
1 parent d7436c0 commit 0243aab

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "Netty NIO HTTP Client",
3+
"type": "bugfix",
4+
"description": "Preserve interrupted flag if `Http2MultiplexedChannelPool#close()` interrupted."
5+
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/http2/Http2MultiplexedChannelPool.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ public void close() {
180180
}
181181
connectionPool.close();
182182
} catch (InterruptedException ie) {
183+
Thread.currentThread().interrupt();
183184
throw new RuntimeException(ie);
184185
}
185186
}

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/http2/Http2MultiplexedChannelPoolTest.java

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,17 @@
2626
import org.junit.AfterClass;
2727
import org.junit.BeforeClass;
2828
import org.junit.Test;
29-
import org.junit.runner.RunWith;
3029
import org.mockito.InOrder;
3130
import org.mockito.Mockito;
32-
import org.mockito.runners.MockitoJUnitRunner;
3331

3432
import java.util.Collections;
33+
import java.util.concurrent.CompletableFuture;
3534

3635
import static org.assertj.core.api.Assertions.assertThat;
3736

38-
3937
/**
4038
* Tests for {@link Http2MultiplexedChannelPool}.
4139
*/
42-
@RunWith(MockitoJUnitRunner.class)
4340
public class Http2MultiplexedChannelPoolTest {
4441
private static EventLoopGroup loopGroup;
4542

@@ -93,4 +90,45 @@ public void acquireAfterCloseFails() throws InterruptedException {
9390

9491
assertThat(h2Pool.acquire().await().isSuccess()).isFalse();
9592
}
93+
94+
@Test(timeout = 5_000)
95+
public void interruptDuringClosePreservesFlag() throws InterruptedException {
96+
SocketChannel channel = new NioSocketChannel();
97+
try {
98+
loopGroup.register(channel).awaitUninterruptibly();
99+
Promise<Channel> channelPromise = new DefaultPromise<>(loopGroup.next());
100+
channelPromise.setSuccess(channel);
101+
102+
ChannelPool connectionPool = Mockito.mock(ChannelPool.class);
103+
Promise<Void> releasePromise = Mockito.spy(new DefaultPromise<>(loopGroup.next()));
104+
105+
Mockito.when(connectionPool.release(Mockito.eq(channel))).thenReturn(releasePromise);
106+
107+
MultiplexedChannelRecord record = new MultiplexedChannelRecord(channelPromise,
108+
channel,
109+
8,
110+
(ch, rec) -> {
111+
});
112+
Http2MultiplexedChannelPool h2Pool = new Http2MultiplexedChannelPool(connectionPool, loopGroup.next(), 2, Collections.singletonList(record));
113+
114+
CompletableFuture<Boolean> interrupteFlagPreserved = new CompletableFuture<>();
115+
116+
Thread t = new Thread(() -> {
117+
try {
118+
h2Pool.close();
119+
} catch (Exception e) {
120+
if (e.getCause() instanceof InterruptedException && Thread.currentThread().isInterrupted()) {
121+
interrupteFlagPreserved.complete(true);
122+
}
123+
}
124+
});
125+
126+
t.start();
127+
t.interrupt();
128+
t.join();
129+
assertThat(interrupteFlagPreserved.join()).isTrue();
130+
} finally {
131+
channel.close().awaitUninterruptibly();
132+
}
133+
}
96134
}

0 commit comments

Comments
 (0)