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

mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git


The following commit(s) were added to refs/heads/master by this push:
     new 3642be0ab [ISSUE #4695] Fix tcp client not thread safe (#4696)
3642be0ab is described below

commit 3642be0abff4a7e649200bc888f481f681b25109
Author: Karson <[email protected]>
AuthorDate: Wed Jan 3 11:26:23 2024 +0800

    [ISSUE #4695] Fix tcp client not thread safe (#4696)
    
    * fix tcp client thread not safe
    
    * fix bug
    
    * fix bug
    
    * fix bug
    
    * fix bug
    
    * fix bug
    
    * fix bug
    
    * fix style problem
    
    * fix style problem
    
    * fix style problem
---
 .../main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java  | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git 
a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java
 
b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java
index a8b164c6d..fed4af541 100644
--- 
a/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java
+++ 
b/eventmesh-sdks/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java
@@ -181,9 +181,8 @@ public abstract class TcpClient implements Closeable {
     protected Package io(Package msg, long timeout) throws Exception {
         Object key = RequestContext.key(msg);
         RequestContext context = RequestContext.context(key, msg);
-        if (!contexts.containsValue(context)) {
-            contexts.put(key, context);
-        } else {
+        RequestContext previousContext = contexts.putIfAbsent(key, context);
+        if (previousContext != null) {
             LogUtils.info(log, "duplicate key : {}", key);
         }
         send(msg);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to