Skip to content

Commit bec30b1

Browse files
authored
Merge pull request #1246 from fl4via/UNDERTOW-1910
[UNDERTOW-1910] Remove UndertowOptions.DEFAULT_WRITE_TIMEOUT, and add…
2 parents 47b96f2 + 7582e96 commit bec30b1

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

core/src/main/java/io/undertow/UndertowOptions.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
* @author Stuart Douglas
2525
*/
2626
public class UndertowOptions {
27-
28-
/**
29-
* The maximum timeout to wait on awaitWritable in milisseconds when not specified.
30-
*/
31-
public static final int DEFAULT_WRITE_TIMEOUT = 600000;
32-
3327
/**
3428
* The maximum size in bytes of a http request header.
3529
*/

core/src/main/java/io/undertow/server/protocol/framed/AbstractFramedStreamSinkChannel.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@
2222
import java.io.InterruptedIOException;
2323
import java.nio.ByteBuffer;
2424
import java.nio.channels.FileChannel;
25+
import java.security.AccessController;
26+
import java.security.PrivilegedAction;
2527
import java.util.concurrent.TimeUnit;
2628
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
2729

2830
import io.undertow.UndertowLogger;
2931
import io.undertow.UndertowMessages;
30-
import io.undertow.UndertowOptions;
3132
import io.undertow.connector.PooledByteBuffer;
3233
import io.undertow.util.ImmediatePooledByteBuffer;
3334
import org.xnio.Buffers;
3435
import org.xnio.ChannelListener;
3536
import org.xnio.ChannelListeners;
3637
import org.xnio.IoUtils;
3738
import org.xnio.Option;
38-
import org.xnio.Options;
3939
import org.xnio.XnioExecutor;
4040
import org.xnio.XnioIoThread;
4141
import org.xnio.XnioWorker;
@@ -59,6 +59,17 @@
5959
*/
6060
public abstract class AbstractFramedStreamSinkChannel<C extends AbstractFramedChannel<C, R, S>, R extends AbstractFramedStreamSourceChannel<C, R, S>, S extends AbstractFramedStreamSinkChannel<C, R, S>> implements StreamSinkChannel {
6161

62+
63+
/**
64+
* The maximum timeout to wait on awaitWritable in milliseconds when not specified.
65+
*/
66+
private static final int AWAIT_WRITABLE_TIMEOUT;
67+
68+
static {
69+
final int defaultAwaitWritableTimeout = 600000;
70+
int await_writable_timeout = AccessController.doPrivileged((PrivilegedAction<Integer>) () -> Integer.getInteger("io.undertow.await_writable_timeout", defaultAwaitWritableTimeout));
71+
AWAIT_WRITABLE_TIMEOUT = await_writable_timeout > 0? await_writable_timeout : defaultAwaitWritableTimeout;
72+
}
6273
private static final PooledByteBuffer EMPTY_BYTE_BUFFER = new ImmediatePooledByteBuffer(ByteBuffer.allocateDirect(0));
6374

6475
private final C channel;
@@ -112,20 +123,11 @@ public abstract class AbstractFramedStreamSinkChannel<C extends AbstractFramedCh
112123
private volatile int inListenerLoop;
113124
/* keep track of successful writes to properly prevent a loop UNDERTOW-1624 */
114125
private volatile boolean writeSucceeded;
115-
/** Timeout used by awaitWritable (ms) */
116-
private final long awaitWritableTimeout;
117126

118127
private static final AtomicIntegerFieldUpdater<AbstractFramedStreamSinkChannel> inListenerLoopUpdater = AtomicIntegerFieldUpdater.newUpdater(AbstractFramedStreamSinkChannel.class, "inListenerLoop");
119128

120129
protected AbstractFramedStreamSinkChannel(C channel) {
121130
this.channel = channel;
122-
Integer writeTimeout = null;
123-
try {
124-
writeTimeout = channel.getOption(Options.WRITE_TIMEOUT);
125-
} catch (IOException e) {
126-
UndertowLogger.ROOT_LOGGER.ioException(e);
127-
}
128-
awaitWritableTimeout = writeTimeout != null && writeTimeout > 0? writeTimeout : UndertowOptions.DEFAULT_WRITE_TIMEOUT;
129131
}
130132

131133
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException {
@@ -296,7 +298,7 @@ public void awaitWritable() throws IOException {
296298
waiterCount++;
297299
//we need to re-check after incrementing the waiters count
298300
if(readyForFlush && !anyAreSet(state, STATE_CLOSED) && !broken) {
299-
lock.wait(awaitWritableTimeout);
301+
lock.wait(AWAIT_WRITABLE_TIMEOUT);
300302
}
301303
} catch (InterruptedException e) {
302304
Thread.currentThread().interrupt();
@@ -481,7 +483,7 @@ protected boolean safeToSend() throws IOException {
481483
* @return the awaitWritable timeout, in milliseconds
482484
*/
483485
protected long getAwaitWritableTimeout() {
484-
return this.awaitWritableTimeout;
486+
return AWAIT_WRITABLE_TIMEOUT;
485487
}
486488

487489
@Override

0 commit comments

Comments
 (0)