Skip to content

Commit b01c241

Browse files
committed
BZ 66281 - unexpected timeouts when using HTTP/2 and NIO2
Timeouts may appear as client disconnections https://bz.apache.org/bugzilla/show_bug.cgi?id=66281
1 parent a0fd011 commit b01c241

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

java/org/apache/coyote/http2/Http2UpgradeHandler.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ public void init(WebConnection webConnection) {
274274
throw new ProtocolException(sm.getString("upgradeHandler.pingFailed"), ioe);
275275
}
276276

277+
// Allow streams and connection to determine timeouts
278+
socketWrapper.setReadTimeout(-1);
279+
socketWrapper.setWriteTimeout(-1);
280+
277281
if (webConnection != null) {
278282
processStreamOnContainerThread(stream);
279283
}
@@ -337,10 +341,7 @@ public SocketState upgradeDispatch(SocketEvent status) {
337341
}
338342
}
339343
try {
340-
// There is data to read so use the read timeout while
341-
// reading frames ...
342-
socketWrapper.setReadTimeout(getReadTimeout());
343-
// ... and disable the connection timeout
344+
// Disable the connection timeout while frames are processed
344345
setConnectionTimeout(-1);
345346
while (true) {
346347
try {
@@ -1603,6 +1604,15 @@ public boolean fill(boolean block, byte[] data, int offset, int length) throws I
16031604
int thisRead = 0;
16041605

16051606
while (len > 0) {
1607+
// Blocking reads use the protocol level read timeout. Non-blocking
1608+
// reads do not timeout. The intention is that once a frame has
1609+
// started to be read, the read timeout applies until it is
1610+
// completely read.
1611+
if (nextReadBlock) {
1612+
socketWrapper.setReadTimeout(protocol.getReadTimeout());
1613+
} else {
1614+
socketWrapper.setReadTimeout(-1);
1615+
}
16061616
thisRead = socketWrapper.read(nextReadBlock, data, pos, len);
16071617
if (thisRead == 0) {
16081618
if (nextReadBlock) {

webapps/docs/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@
186186
<bug>66276</bug>: Fix incorrect class cast when adding
187187
a descendant of HTTP/2 streams. (lihan)
188188
</fix>
189+
<fix>
190+
<bug>66281</bug>: Fix unexpected timeouts that may appear as client
191+
disconnections when using HTTP/2 and NIO2. (markt)
192+
</fix>
189193
</changelog>
190194
</subsection>
191195
<subsection name="Jasper">

0 commit comments

Comments
 (0)