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

UNDERTOW-2018: Fix NPE in FixedLengthStreamSourceConduit on failure #1289

Merged
merged 1 commit into from Feb 6, 2022
Merged
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
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());
}
}

}