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-2298] Avoid NPE on concurrent close/timeout #1509

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import static org.jboss.logging.Logger.Level.ERROR;
import static org.jboss.logging.Logger.Level.WARN;
import static org.jboss.logging.Logger.Level.TRACE;

/**
* log messages start at 15000
Expand Down Expand Up @@ -140,4 +141,7 @@ public interface UndertowServletLogger extends BasicLogger {
@Message(id = 15024, value = "Servlet %s init() method in web application %s threw exception")
void failedToLoad(String servletName, String appName, @Cause Throwable t);

@LogMessage(level = TRACE)
@Message(id = 15025, value = "IO Operation de-synchronization trace: ")
void ioOperationDesynchronization( @Cause Throwable t);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.xnio.channels.StreamSourceChannel;
import io.undertow.connector.ByteBufferPool;
import io.undertow.connector.PooledByteBuffer;
import io.undertow.servlet.UndertowServletLogger;
import io.undertow.servlet.UndertowServletMessages;

/**
Expand Down Expand Up @@ -196,14 +197,21 @@ public int read(final byte[] b, final int off, final int len) throws IOException

private void readIntoBuffer() throws IOException {
if (pooled == null && !anyAreSet(state, FLAG_FINISHED)) {
pooled = bufferPool.allocate();
try {
pooled = bufferPool.allocate();

int res = Channels.readBlocking(channel, pooled.getBuffer());
pooled.getBuffer().flip();
if (res == -1) {
setFlags(FLAG_FINISHED);
pooled.close();
pooled = null;
int res = Channels.readBlocking(channel, pooled.getBuffer());
pooled.getBuffer().flip();
if (res == -1) {
setFlags(FLAG_FINISHED);
pooled.close();
pooled = null;
}
} catch(NullPointerException npe) {
//UNDERTOW-2298 - this will happen in small window when read is happening and timeout happens
if (!(anyAreSet(state, FLAG_CLOSED) || isFinished())) {
UndertowServletLogger.ROOT_LOGGER.ioOperationDesynchronization(npe);
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -932,4 +932,9 @@
<Match>
<Package name="io.undertow.benchmarks"/>
</Match>
<Match>
<Bug pattern="DCN_NULLPOINTER_EXCEPTION"/>
<Class name="io.undertow.servlet.spec.ServletInputStreamImpl"/>
<Method name="readIntoBuffer"/>
</Match>
</FindBugsFilter>
Loading