private CompletableFuture < Void > stopContainer ( int containerId ) { log . info ( "Stopping Container {}." , containerId ) ; ContainerHandle handle = handles . get ( containerId ) ; if ( handle == null ) { log . warn ( "Container {} handle is null, container is pending start or already unregistered." , containerId ) ; return null ; } else { this . pendingTasks . add ( containerId ) ; try { return registry . stopContainer ( handle , CLOSE_TIMEOUT_PER_CONTAINER ) . whenComplete ( ( aVoid , throwable ) -> { if ( throwable != null ) { log . warn ( "Stopping container {} failed: {}" , containerId , throwable ) ; } try { // We remove the handle and don't attempt retry on stop container failures. unregisterHandle ( containerId ) ; } finally { // The pending task has to be removed after the handle is removed to avoid inconsistencies // with the container state. // Using finally block to ensure this is always called, otherwise this will prevent other // tasks from being attempted for this container id. this . pendingTasks . remove ( containerId ) ; } } ) ; } catch ( Throwable e ) { // The pending task has to be removed on all failures to enable retries. this . pendingTasks . remove ( containerId ) ; throw e ; } } }
Stop the container given its id .