You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/09/15 13:30:14 UTC

[httpcomponents-core] 03/09: HTTPCORE-753: fixed race condition in the IOSession#close method

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

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

commit a56b38360b7353485ae35fc3b8810a8206d7780f
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Tue Jun 27 12:57:28 2023 +0200

    HTTPCORE-753: fixed race condition in the IOSession#close method
---
 .../src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
index c9439cbba..19235f575 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/reactor/IOSessionImpl.java
@@ -263,8 +263,13 @@ class IOSessionImpl implements IOSession {
                     // Quietly ignore
                 }
             }
-            this.key.cancel();
-            this.key.attach(null);
+            lock.lock();
+            try {
+                this.key.cancel();
+                this.key.attach(null);
+            } finally {
+                lock.unlock();
+            }
             Closer.closeQuietly(this.key.channel());
             if (this.key.selector().isOpen()) {
                 this.key.selector().wakeup();