protect event schedule race

This commit is contained in:
Greg Wilkins 2015-02-26 15:37:51 +11:00
parent 752973931e
commit af70c4bd48
3 changed files with 12 additions and 15 deletions

View File

@ -291,7 +291,7 @@ public class HttpChannelState
protected Action unhandle() protected Action unhandle()
{ {
Action action; Action action;
boolean schedule_timeout=false; AsyncContextEvent schedule_event=null;
boolean read_interested=false; boolean read_interested=false;
if(DEBUG) if(DEBUG)
@ -344,9 +344,9 @@ public class HttpChannelState
_state=State.ASYNC_IO; _state=State.ASYNC_IO;
action = Action.WRITE_CALLBACK; action = Action.WRITE_CALLBACK;
} }
else else
{ {
schedule_timeout=true; schedule_event=_event;
read_interested=_asyncReadUnready; read_interested=_asyncReadUnready;
_state=State.ASYNC_WAIT; _state=State.ASYNC_WAIT;
action = Action.WAIT; action = Action.WAIT;
@ -354,7 +354,7 @@ public class HttpChannelState
break; break;
case EXPIRING: case EXPIRING:
schedule_timeout=true; schedule_event=_event;
_state=State.ASYNC_WAIT; _state=State.ASYNC_WAIT;
action = Action.WAIT; action = Action.WAIT;
break; break;
@ -372,8 +372,8 @@ public class HttpChannelState
} }
} }
if (schedule_timeout) if (schedule_event!=null)
scheduleTimeout(); scheduleTimeout(schedule_event);
if (read_interested) if (read_interested)
_channel.asyncReadFillInterested(); _channel.asyncReadFillInterested();
return action; return action;
@ -611,11 +611,11 @@ public class HttpChannelState
_channel.execute(_channel); _channel.execute(_channel);
} }
protected void scheduleTimeout() protected void scheduleTimeout(AsyncContextEvent event)
{ {
Scheduler scheduler = _channel.getScheduler(); Scheduler scheduler = _channel.getScheduler();
if (scheduler!=null && _timeoutMs>0) if (scheduler!=null && _timeoutMs>0)
_event.setTimeoutTask(scheduler.schedule(_event,_timeoutMs,TimeUnit.MILLISECONDS)); event.setTimeoutTask(scheduler.schedule(event,_timeoutMs,TimeUnit.MILLISECONDS));
} }
protected void cancelTimeout() protected void cancelTimeout()

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.server; package org.eclipse.jetty.server;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.Reference;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.WritePendingException; import java.nio.channels.WritePendingException;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
@ -70,7 +69,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
private final BlockingReadCallback _blockingReadCallback = new BlockingReadCallback(); private final BlockingReadCallback _blockingReadCallback = new BlockingReadCallback();
private final AsyncReadCallback _asyncReadCallback = new AsyncReadCallback(); private final AsyncReadCallback _asyncReadCallback = new AsyncReadCallback();
private final SendCallback _sendCallback = new SendCallback(); private final SendCallback _sendCallback = new SendCallback();
/** /**
* Get the current connection that this thread is dispatched to. * Get the current connection that this thread is dispatched to.
* Note that a thread may be processing a request asynchronously and * Note that a thread may be processing a request asynchronously and
@ -200,7 +199,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
if (_requestBuffer == null) if (_requestBuffer == null)
_requestBuffer = _bufferPool.acquire(getInputBufferSize(), REQUEST_BUFFER_DIRECT); _requestBuffer = _bufferPool.acquire(getInputBufferSize(), REQUEST_BUFFER_DIRECT);
return _requestBuffer; return _requestBuffer;
} }
public boolean isRequestBufferEmpty() public boolean isRequestBufferEmpty()
@ -221,10 +220,10 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
{ {
// Fill the request buffer (if needed) // Fill the request buffer (if needed)
int filled = fillRequestBuffer(); int filled = fillRequestBuffer();
// Parse the request buffer // Parse the request buffer
boolean handle = parseRequestBuffer(); boolean handle = parseRequestBuffer();
// Handle close parser // Handle close parser
if (_parser.isClose()) if (_parser.isClose())
{ {
@ -258,7 +257,6 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
LOG.debug("{} onFillable exit {}", this, _channel.getState()); LOG.debug("{} onFillable exit {}", this, _channel.getState());
} }
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** Fill and parse data looking for content /** Fill and parse data looking for content

View File

@ -126,7 +126,6 @@ public class HttpInputIntegrationTest
// HTTP/2 Connector // HTTP/2 Connector
ServerConnector http2Connector = ServerConnector http2Connector =
new ServerConnector(__server,ssl,/*TODO alpn,h2,*/ h1); new ServerConnector(__server,ssl,/*TODO alpn,h2,*/ h1);
http2Connector.setPort(8443);
__server.addConnector(http2Connector); __server.addConnector(http2Connector);