Skip to content

Commit

Permalink
Fixed close problems in NioOutboundPipeline
Browse files Browse the repository at this point in the history
There are 2 problems:
* tmp stall because a task is execute on the io thread from
  that same io thread and then the io thread waits for it. Because
  the thread will not execute its own task (yet) you have a 3s stall
  in the io pipeline. This is a big problem because is blocks all traffic
  for that io thread.

* the close task is scheduled as a 'packet'. If the pipeline already is
  scheduled, scheduling the close task will not get picked up as part
  of an optimization.

This pr fixes the above problems.
  • Loading branch information
pveentjer committed Jun 26, 2018
1 parent 3c535c5 commit a906dda
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,24 @@ public void close() {
urgentWriteQueue.clear();

CloseTask closeTask = new CloseTask();
write(new TaskFrame(closeTask));
closeTask.awaitCompletion();
NioThread owner = this.owner;
Thread currentThread = Thread.currentThread();
if (currentThread instanceof NioThread) {
if (currentThread == owner) {
// we don't schedule the task, we execute it immediately
// This will prevent waiting on a task this thread is
// supposed to execute, but can't. And therefor runs into
// a temporary stall.
closeTask.run();
}

// if the currentThread isn't the owner, there
// is a migration happening and we can't close
} else {
// closing is executed from a non-io thread, so we can block
owner.addTaskAndWakeup(closeTask);
closeTask.awaitCompletion();
}
}

@Override
Expand Down Expand Up @@ -438,6 +454,12 @@ private class CloseTask implements Runnable {

@Override
public void run() {
NioThread owner = NioOutboundPipeline.this.owner;
if (owner != Thread.currentThread()) {
owner.addTaskAndWakeup(this);
return;
}

try {
channel.closeOutbound();
} catch (IOException e) {
Expand Down

0 comments on commit a906dda

Please sign in to comment.