Skip to content

Commit

Permalink
Fixes #1920 - Connect Timeouts with NonBlocking CreateEndPoint.
Browse files Browse the repository at this point in the history
Made CreateEndPoint a blocking task, because it calls into application
code via Connection.Listener, and for safety we assume it may be
blocking code, avoiding to stall the processing of NIO selected keys.
  • Loading branch information
sbordet committed Oct 25, 2017
1 parent 2bd39c8 commit bfaa2d5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java
Expand Up @@ -159,7 +159,7 @@ private Runnable processConnect(SelectionKey key, final Connect connect)
if (connect.timeout.cancel())
{
key.interestOps(0);
return new CreateEndPoint(channel, key, InvocationType.BLOCKING)
return new CreateEndPoint(channel, key)
{
@Override
protected void failed(Throwable failure)
Expand Down Expand Up @@ -199,19 +199,17 @@ private void closeNoExceptions(Closeable closeable)
}
}

private EndPoint createEndPoint(SelectableChannel channel, SelectionKey selectionKey) throws IOException
private void createEndPoint(SelectableChannel channel, SelectionKey selectionKey) throws IOException
{
EndPoint endPoint = _selectorManager.newEndPoint(channel, this, selectionKey);
Connection connection = _selectorManager.newConnection(channel, endPoint, selectionKey.attachment());
endPoint.setConnection(connection);
selectionKey.attach(endPoint);

endPoint.onOpen();
_selectorManager.endPointOpened(endPoint);
_selectorManager.connectionOpened(connection);
if (LOG.isDebugEnabled())
LOG.debug("Created {}", endPoint);
return endPoint;
}

public void destroyEndPoint(final EndPoint endPoint)
Expand Down Expand Up @@ -595,7 +593,7 @@ public void run()
try
{
final SelectionKey key = channel.register(_selector, 0, attachment);
submit(new CreateEndPoint(channel, key, InvocationType.NON_BLOCKING));
submit(new CreateEndPoint(channel, key));
}
catch (Throwable x)
{
Expand All @@ -609,13 +607,11 @@ private class CreateEndPoint implements Runnable, Invocable, Closeable
{
private final SelectableChannel channel;
private final SelectionKey key;
private final InvocationType invocationType;

public CreateEndPoint(SelectableChannel channel, SelectionKey key, InvocationType invocationType)
public CreateEndPoint(SelectableChannel channel, SelectionKey key)
{
this.channel = channel;
this.key = key;
this.invocationType = invocationType;
}

@Override
Expand All @@ -632,12 +628,6 @@ public void run()
}
}

@Override
public InvocationType getInvocationType()
{
return invocationType;
}

@Override
public void close()
{
Expand Down

0 comments on commit bfaa2d5

Please sign in to comment.