Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EtcdDataSource#initWatcher make "Thread blocked" #3004

Closed
LProDreamAll opened this issue Dec 23, 2022 · 2 comments
Closed

EtcdDataSource#initWatcher make "Thread blocked" #3004

LProDreamAll opened this issue Dec 23, 2022 · 2 comments
Labels
area/data-source Issues or PRs related to data-source extension kind/bug Category issues or prs related to bug.

Comments

@LProDreamAll
Copy link

EtcdDataSource#initWatcher make "Thread blocked"

The EtcdDataSource class reported Thread blocked When using etcd to manage rules

  1. WARN 49121 --- [-thread-checker] io.vertx.core.impl.BlockedThreadChecker : Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 5225 ms, time limit is 2000 ms.
    io.vertx.core.VertxException: Thread blocked
    at sun.misc.Unsafe.park(Native Method) ~[na:1.8.0_221]
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) ~[na:1.8.0_221]
    at java.util.concurrent.CompletableFuture$Signaller.block(CompletableFuture.java:1693) ~[na:1.8.0_221]
    at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3323) ~[na:1.8.0_221]
    at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:1729) ~[na:1.8.0_221]
    at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895) ~[na:1.8.0_221]
    at com.alibaba.csp.sentinel.datasource.etcd.EtcdDataSource.readSource(EtcdDataSource.java:114) ~[classes/:na]

com.alibaba.csp.sentinel.datasource.etcd.EtcdDataSource#initWatcher

private void initWatcher() {
watcher = client.getWatchClient().watch(ByteSequence.from(key, charset), (watchResponse) -> {
for (WatchEvent watchEvent : watchResponse.getEvents()) {
WatchEvent.EventType eventType = watchEvent.getEventType();
if (eventType == WatchEvent.EventType.PUT) {
try {
T newValue = loadConfig();
getProperty().updateValue(newValue);
} catch (Exception e) {
RecordLog.warn("[EtcdDataSource] Failed to update config", e);
}
} else if (eventType == WatchEvent.EventType.DELETE) {
RecordLog.info("[EtcdDataSource] Cleaning config for key <{}>", key);
getProperty().updateValue(null);
}
}
});
}

Solution

private void initWatcher() {
watcher = client.getWatchClient().watch(ByteSequence.from(key, charset), (watchResponse) -> {
for (WatchEvent watchEvent : watchResponse.getEvents()) {
WatchEvent.EventType eventType = watchEvent.getEventType();
final String nodeValue = watchEvent.getKeyValue().getValue().toString(StandardCharsets.UTF_8);
if (eventType == WatchEvent.EventType.PUT) {
try {
T newValue = parser.convert(nodeValue);
getProperty().updateValue(newValue);
} catch (Exception e) {
RecordLog.warn("[EtcdDataSource] Failed to update config", e);
}
} else if (eventType == WatchEvent.EventType.DELETE) {
RecordLog.info("[EtcdDataSource] Cleaning config for key <{}>", key);
getProperty().updateValue(null);
}
}
});
}

@sczyh30 sczyh30 added the area/data-source Issues or PRs related to data-source extension label Dec 23, 2022
@sczyh30
Copy link
Member

sczyh30 commented Dec 23, 2022

Please refer #2991

@LProDreamAll
Copy link
Author

LProDreamAll commented Dec 23, 2022

@sczyh30 I close that

@sczyh30 sczyh30 added the kind/bug Category issues or prs related to bug. label Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/data-source Issues or PRs related to data-source extension kind/bug Category issues or prs related to bug.
Projects
None yet
Development

No branches or pull requests

2 participants