zhuzhurk commented on a change in pull request #12181:
URL: https://github.com/apache/flink/pull/12181#discussion_r427010925
##########
File path:
flink-core/src/main/java/org/apache/flink/core/fs/SafetyNetCloseableRegistry.java
##########
@@ -73,8 +73,34 @@
synchronized (REAPER_THREAD_LOCK) {
if (0 == GLOBAL_SAFETY_NET_REGISTRY_COUNT) {
Preconditions.checkState(null == REAPER_THREAD);
- REAPER_THREAD = new CloseableReaperThread();
- REAPER_THREAD.start();
+ try {
+ REAPER_THREAD = new
CloseableReaperThread();
+ REAPER_THREAD.start();
+ } catch (Throwable throwable) {
+ // thread create or start error.
+ REAPER_THREAD = null;
+ throw throwable;
+ }
+ }
+ ++GLOBAL_SAFETY_NET_REGISTRY_COUNT;
+ }
+ }
+
+ @VisibleForTesting
+ SafetyNetCloseableRegistry(CloseableReaperThread reaperThread) {
Review comment:
We should avoid duplicating the codes.
Below is a possible way to make it.
```
SafetyNetCloseableRegistry() {
this(() -> new CloseableReaperThread());
}
@VisibleForTesting
SafetyNetCloseableRegistry(Supplier<CloseableReaperThread>
reaperThreadSupplier) {
super(new IdentityHashMap<>());
synchronized (REAPER_THREAD_LOCK) {
if (0 == GLOBAL_SAFETY_NET_REGISTRY_COUNT) {
Preconditions.checkState(null == REAPER_THREAD);
try {
REAPER_THREAD =
reaperThreadSupplier.get();
REAPER_THREAD.start();
} catch (Throwable throwable) {
REAPER_THREAD = null;
throw throwable;
}
}
++GLOBAL_SAFETY_NET_REGISTRY_COUNT;
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]