From cbc5dac6c4fd8e2fe71758ee2a81139db5f332d7 Mon Sep 17 00:00:00 2001 From: Kai Yang Date: Tue, 20 Oct 2020 22:31:27 +0800 Subject: [PATCH] [Java] fix shutdown lock typo (#11410) --- .../src/main/java/io/ray/runtime/RayNativeRuntime.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/runtime/src/main/java/io/ray/runtime/RayNativeRuntime.java b/java/runtime/src/main/java/io/ray/runtime/RayNativeRuntime.java index b6059ce16..32663e391 100644 --- a/java/runtime/src/main/java/io/ray/runtime/RayNativeRuntime.java +++ b/java/runtime/src/main/java/io/ray/runtime/RayNativeRuntime.java @@ -174,7 +174,11 @@ public final class RayNativeRuntime extends AbstractRayRuntime { @Override public void shutdown() { - Lock writeLock = shutdownLock.readLock(); + // `shutdown` won't be called concurrently, but the lock is also used in `NativeObjectStore`. + // When an object is garbage collected, the object will be unregistered from core worker. + // Since GC runs in a separate thread, we need to make sure that core worker is available + // when `NativeObjectStore` is accessing core worker in the GC thread. + Lock writeLock = shutdownLock.writeLock(); writeLock.lock(); try { if (rayConfig.workerMode == WorkerType.DRIVER) {