hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [4/7] httpcomponents-core git commit: Fixed status notification bug in IOReactorImpl shutdown code
Date Thu, 15 Jun 2017 05:59:35 GMT
Fixed status notification bug in IOReactorImpl shutdown code


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/43714ada
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/43714ada
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/43714ada

Branch: refs/heads/master
Commit: 43714ada233de6a7a82291d55e5df2fcc32b2ebb
Parents: fca2a30
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Thu Jun 8 14:17:20 2017 +0200
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Wed Jun 14 19:07:19 2017 +0200

----------------------------------------------------------------------
 .../reactor/AbstractMultiworkerIOReactor.java   |  2 --
 .../apache/hc/core5/reactor/IOReactorImpl.java  | 22 +++++++++++++-------
 2 files changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/43714ada/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
index 1ea7634..76c4542 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/AbstractMultiworkerIOReactor.java
@@ -31,9 +31,7 @@ import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.net.Socket;
 import java.nio.channels.Channel;
-import java.nio.channels.ClosedChannelException;
 import java.nio.channels.ClosedSelectorException;
-import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/43714ada/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
----------------------------------------------------------------------
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
index 9671aca..e0f0c94 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOReactorImpl.java
@@ -176,9 +176,8 @@ class IOReactorImpl implements IOReactor {
                 }
 
                 // Exit select loop if graceful shutdown has been completed
-                if (this.status.get().compareTo(IOReactorStatus.SHUTTING_DOWN) == 0
-                        && this.selector.keys().isEmpty()) {
-                    this.status.set(IOReactorStatus.SHUT_DOWN);
+                if (this.status.get().compareTo(IOReactorStatus.SHUTTING_DOWN) == 0 &&
this.selector.keys().isEmpty()) {
+                    break;
                 }
                 if (this.status.get().compareTo(IOReactorStatus.SHUT_DOWN) == 0) {
                     break;
@@ -367,14 +366,23 @@ class IOReactorImpl implements IOReactor {
 
     @Override
     public void initiateShutdown() {
-        if (this.status.compareAndSet(IOReactorStatus.ACTIVE, IOReactorStatus.SHUTTING_DOWN))
{
-            selector.wakeup();
+        if (this.status.compareAndSet(IOReactorStatus.INACTIVE, IOReactorStatus.SHUT_DOWN))
{
+            synchronized (this.shutdownMutex) {
+                this.shutdownMutex.notifyAll();
+            }
+        } else if (this.status.compareAndSet(IOReactorStatus.ACTIVE, IOReactorStatus.SHUTTING_DOWN))
{
+            this.selector.wakeup();
         }
     }
 
     void forceShutdown() {
-        this.status.set(IOReactorStatus.SHUT_DOWN);
-        this.selector.wakeup();
+        final IOReactorStatus previousStatus = this.status.getAndSet(IOReactorStatus.SHUT_DOWN);
+        if (previousStatus.compareTo(IOReactorStatus.ACTIVE) == 0) {
+            this.selector.wakeup();
+        }
+        synchronized (this.shutdownMutex) {
+            this.shutdownMutex.notifyAll();
+        }
     }
 
     @Override


Mime
View raw message