Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
Fix concurrent modification exception. (#1493)
Browse files Browse the repository at this point in the history
### Motivation

There is some flaky test when we stop the brokers.
```
Error:  Failures:
Error:    CacheInvalidatorTest.cleanup:111->KopProtocolHandlerTestBase.internalCleanup:319->KopProtocolHandlerTestBase.stopBroker:355->KopProtocolHandlerTestBase.stopBroker:351 » PulsarServer
Error:    TransactionWithOAuthBearerAuthTest.cleanup:72->TransactionTest.cleanup:77->KopProtocolHandlerTestBase.internalCleanup:319->KopProtocolHandlerTestBase.stopBroker:355->KopProtocolHandlerTestBase.stopBroker:351 » PulsarServer
```

The root cause is when we close the `TransactionMarkerChannelManager`,
we will traverse all entries of `handlerMap`,
but some of the entry already been removed,
we can use `ConcurrentHashMap` to avoid it.

### Modifications

Use `ConcurrentHashMap` instead of `HashMap`.

(cherry picked from commit 533efbd)
  • Loading branch information
Demogorgon314 committed Sep 15, 2022
1 parent e9a5405 commit 25c2152
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -79,7 +78,8 @@ public class TransactionMarkerChannelManager {

private final Bootstrap bootstrap;

private Map<InetSocketAddress, CompletableFuture<TransactionMarkerChannelHandler>> handlerMap = new HashMap<>();
private final Map<InetSocketAddress, CompletableFuture<TransactionMarkerChannelHandler>> handlerMap =
new ConcurrentHashMap<>();

private TransactionStateManager txnStateManager;

Expand Down

0 comments on commit 25c2152

Please sign in to comment.