You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2019/12/19 02:22:11 UTC

[httpcomponents-core] branch master updated: AbstractHttp1StreamDuplexer: don't synchronize on `this`

This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git


The following commit(s) were added to refs/heads/master by this push:
     new fd57d35  AbstractHttp1StreamDuplexer: don't synchronize on `this`
fd57d35 is described below

commit fd57d35dd196fb464f10ea72bc7c6880b9b5e4ad
Author: Richard Hernandez <ri...@amazon.com>
AuthorDate: Tue Dec 17 20:56:11 2019 -0800

    AbstractHttp1StreamDuplexer: don't synchronize on `this`
---
 .../http/impl/nio/AbstractHttp1StreamDuplexer.java | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
index 4fe2a88..24aa6b8 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
@@ -576,22 +576,26 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
 
     static class CapacityWindow implements CapacityChannel {
         private final IOSession ioSession;
+        private final Object lock;
         private int window;
         private boolean closed;
 
         CapacityWindow(final int window, final IOSession ioSession) {
             this.window = window;
             this.ioSession = ioSession;
+            this.lock = new Object();
         }
 
         @Override
-        public synchronized void update(final int increment) throws IOException {
-            if (closed) {
-                return;
-            }
-            if (increment > 0) {
-                updateWindow(increment);
-                ioSession.setEvent(SelectionKey.OP_READ);
+        public void update(final int increment) throws IOException {
+            synchronized (lock) {
+                if (closed) {
+                    return;
+                }
+                if (increment > 0) {
+                    updateWindow(increment);
+                    ioSession.setEvent(SelectionKey.OP_READ);
+                }
             }
         }
 
@@ -599,12 +603,14 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
          * Internal method for removing capacity. We don't need to check
          * if this channel is closed in it.
          */
-        synchronized int removeCapacity(final int delta) {
-            updateWindow(-delta);
-            if (window <= 0) {
-                ioSession.clearEvent(SelectionKey.OP_READ);
+        int removeCapacity(final int delta) {
+            synchronized (lock) {
+                updateWindow(-delta);
+                if (window <= 0) {
+                    ioSession.clearEvent(SelectionKey.OP_READ);
+                }
+                return window;
             }
-            return window;
         }
 
         private void updateWindow(final int delta) {
@@ -620,8 +626,10 @@ abstract class AbstractHttp1StreamDuplexer<IncomingMessage extends HttpMessage,
          * Closes the capacity channel, preventing user code from accidentally requesting
          * read events outside of the context of the request the channel was created for
          */
-        synchronized void close() {
-            closed = true;
+        void close() {
+            synchronized (lock) {
+                closed = true;
+            }
         }
 
         // visible for testing