Skip to content

Commit 050767c

Browse files
committed
[FLINK-35786] Fix NPE BlobServer / shutdownHook
1 parent 93d7f45 commit 050767c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

flink-runtime/src/main/java/org/apache/flink/runtime/blob/BlobServer.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public class BlobServer extends Thread
9797
private final AtomicLong tempFileCounter = new AtomicLong(0);
9898

9999
/** The server socket listening for incoming connections. */
100-
private final ServerSocket serverSocket;
100+
// can be null if BlobServer is shut down before constructor completion
101+
@Nullable private final ServerSocket serverSocket;
101102

102103
/** Blob Server configuration. */
103104
private final Configuration blobServiceConfiguration;
@@ -354,10 +355,12 @@ public void close() throws IOException {
354355
if (shutdownRequested.compareAndSet(false, true)) {
355356
Exception exception = null;
356357

357-
try {
358-
this.serverSocket.close();
359-
} catch (IOException ioe) {
360-
exception = ioe;
358+
if (serverSocket != null) {
359+
try {
360+
this.serverSocket.close();
361+
} catch (IOException ioe) {
362+
exception = ioe;
363+
}
361364
}
362365

363366
// wake the thread up, in case it is waiting on some operation
@@ -394,10 +397,14 @@ public void close() throws IOException {
394397
ShutdownHookUtil.removeShutdownHook(shutdownHook, getClass().getSimpleName(), LOG);
395398

396399
if (LOG.isInfoEnabled()) {
397-
LOG.info(
398-
"Stopped BLOB server at {}:{}",
399-
serverSocket.getInetAddress().getHostAddress(),
400-
getPort());
400+
if (serverSocket != null) {
401+
LOG.info(
402+
"Stopped BLOB server at {}:{}",
403+
serverSocket.getInetAddress().getHostAddress(),
404+
getPort());
405+
} else {
406+
LOG.info("Stopped BLOB server before initializing the socket");
407+
}
401408
}
402409

403410
ExceptionUtils.tryRethrowIOException(exception);

0 commit comments

Comments
 (0)