@@ -97,7 +97,8 @@ public class BlobServer extends Thread
97
97
private final AtomicLong tempFileCounter = new AtomicLong (0 );
98
98
99
99
/** 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 ;
101
102
102
103
/** Blob Server configuration. */
103
104
private final Configuration blobServiceConfiguration ;
@@ -354,10 +355,12 @@ public void close() throws IOException {
354
355
if (shutdownRequested .compareAndSet (false , true )) {
355
356
Exception exception = null ;
356
357
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
+ }
361
364
}
362
365
363
366
// wake the thread up, in case it is waiting on some operation
@@ -394,10 +397,14 @@ public void close() throws IOException {
394
397
ShutdownHookUtil .removeShutdownHook (shutdownHook , getClass ().getSimpleName (), LOG );
395
398
396
399
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
+ }
401
408
}
402
409
403
410
ExceptionUtils .tryRethrowIOException (exception );
0 commit comments