Skip to content

Commit

Permalink
Merge pull request #13363 from pveentjer/v3.10/fix/NioOutboundPipelin…
Browse files Browse the repository at this point in the history
…e-close

Fixed close problems in NioOutboundPipeline
  • Loading branch information
pveentjer committed Jun 28, 2018
2 parents 5324e0a + a906dda commit d3caf82
Showing 1 changed file with 24 additions and 2 deletions.
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 d3caf82

Please sign in to comment.