Skip to content

Commit

Permalink
Merge pull request #1289 from carterkozak/UNDERTOW-2018
Browse files Browse the repository at this point in the history
UNDERTOW-2018: Fix NPE in FixedLengthStreamSourceConduit on failure
  • Loading branch information
fl4via committed Feb 6, 2022
2 parents 19a17fe + 8e432f6 commit cda3aae
Showing 1 changed file with 12 additions and 5 deletions.
Expand Up @@ -126,7 +126,7 @@ public long transferTo(final long position, final long count, final FileChannel
try {
return res = next.transferTo(position, min(count, val & MASK_COUNT), target);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
closeConnection();
transferError = e;
throw e;
} finally {
Expand All @@ -151,7 +151,7 @@ public long transferTo(final long count, final ByteBuffer throughBuffer, final S
try {
return res = next.transferTo(min(count, val & MASK_COUNT), throughBuffer, target);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
closeConnection();
transferError = e;
throw e;
} finally {
Expand Down Expand Up @@ -219,7 +219,7 @@ public long read(final ByteBuffer[] dsts, final int offset, final int length) th
// the total buffer space is less than the remaining count.
return res = next.read(dsts, offset, length);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
closeConnection();
readError = e;
throw e;
} finally {
Expand Down Expand Up @@ -257,7 +257,7 @@ public int read(final ByteBuffer dst) throws IOException {
return res = next.read(dst);
}
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
closeConnection();
readError = e;
throw e;
} finally {
Expand Down Expand Up @@ -302,7 +302,7 @@ public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOExc
try {
next.awaitReadable(time, timeUnit);
} catch (IOException | RuntimeException | Error e) {
IoUtils.safeClose(exchange.getConnection());
closeConnection();
throw e;
}
}
Expand Down Expand Up @@ -365,4 +365,11 @@ private void invokeFinishListener() {
finishListener.handleEvent(this);
}

private void closeConnection() {
HttpServerExchange exchange = this.exchange;
if (exchange != null) {
IoUtils.safeClose(exchange.getConnection());
}
}

}

0 comments on commit cda3aae

Please sign in to comment.