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

ascherbakov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 0983c2a  IGNITE-14943 Fixed race in ThreadId.setError method - Fixes 
#287.
0983c2a is described below

commit 0983c2a98f510ebbb71d2e4b9f010f64b6174dab
Author: Mirza Aliev <alievmi...@gmail.com>
AuthorDate: Fri Aug 20 18:20:09 2021 +0300

    IGNITE-14943 Fixed race in ThreadId.setError method - Fixes #287.
    
    Signed-off-by: Alexey Scherbakov <alexey.scherbak...@gmail.com>
---
 .../apache/ignite/raft/jraft/core/ITNodeTest.java  |  1 -
 .../apache/ignite/raft/jraft/util/ThreadId.java    | 27 +++++++++++-----------
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git 
a/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
 
b/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
index dbc93c5..95d1c55 100644
--- 
a/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
+++ 
b/modules/raft/src/integrationTest/java/org/apache/ignite/raft/jraft/core/ITNodeTest.java
@@ -2018,7 +2018,6 @@ public class ITNodeTest {
     }
 
     @Test // TODO add test for timeout on snapshot install 
https://issues.apache.org/jira/browse/IGNITE-14832
-    @Disabled("https://issues.apache.org/jira/browse/IGNITE-14943";)
     public void testInstallLargeSnapshotWithThrottle() throws Exception {
         List<PeerId> peers = TestUtils.generatePeers(4);
         cluster = new TestCluster("unitest", dataPath, peers.subList(0, 3));
diff --git 
a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ThreadId.java 
b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ThreadId.java
index 989c584..89fef9c 100644
--- a/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ThreadId.java
+++ b/modules/raft/src/main/java/org/apache/ignite/raft/jraft/util/ThreadId.java
@@ -17,7 +17,6 @@
 package org.apache.ignite.raft.jraft.util;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
 import org.apache.ignite.lang.IgniteLogger;
@@ -27,13 +26,13 @@ import org.apache.ignite.lang.IgniteLogger;
  */
 public class ThreadId {
 
-    private static final IgniteLogger LOG 
=IgniteLogger.forClass(ThreadId.class);
+    private static final IgniteLogger LOG = 
IgniteLogger.forClass(ThreadId.class);
 
     private static final int TRY_LOCK_TIMEOUT_MS = 10;
 
     private final Object data;
     private final NonReentrantLock lock = new NonReentrantLock();
-    private final List<Integer> pendingErrors = 
Collections.synchronizedList(new ArrayList<>());
+    private final List<Integer> pendingErrors = new ArrayList<>();
     private final OnError onError;
     private volatile boolean destroyed;
 
@@ -155,18 +154,20 @@ public class ThreadId {
         if (this.destroyed) {
             return;
         }
-        if (this.lock.tryLock()) {
-            if (this.destroyed) {
-                this.lock.unlock();
-                return;
+        synchronized (pendingErrors) {
+            if (this.lock.tryLock()) {
+                if (this.destroyed) {
+                    this.lock.unlock();
+                    return;
+                }
+                if (this.onError != null) {
+                    // The lock will be unlocked in onError.
+                    this.onError.onError(this, this.data, errorCode);
+                }
             }
-            if (this.onError != null) {
-                // The lock will be unlocked in onError.
-                this.onError.onError(this, this.data, errorCode);
+            else {
+                this.pendingErrors.add(errorCode);
             }
         }
-        else {
-            this.pendingErrors.add(errorCode);
-        }
     }
 }

Reply via email to