Datanode sometimes does not shutdown because the block pool scanner thread keeps running. It prints out "Starting a new period" every five seconds, even after shutdown() is called. Somehow the interrupt is missed.
DataBlockScanner will also terminate if datanode.shouldRun is false, but in DataNode#shutdown, DataBlockScanner#shutdown() is invoked before it is being set to false.
Is there any reason why datanode.shouldRun is set to false later?