hardStop();
} else {
// enforce stop and clean-up even if process has been quickly stopped
- stopForcibly();
+ finalizeStop();
}
} else {
// already stopping or stopped
LOG.info("{} failed to stop in a quick fashion. Killing it.", processId.getKey());
}
// enforce stop and clean-up even if process has been quickly stopped
- stopForcibly();
+ finalizeStop();
} else {
// already stopping or stopped
waitForDown();
return new InterruptedException(errorMessage);
}
- public void stopForcibly() {
+ private void finalizeStop() {
interrupt(eventWatcher);
interrupt(stopWatcher);
if (process != null) {
Thread.currentThread().interrupt();
// stop watching process
}
- stopForcibly();
+ // since process is already stopped, this will only finalize the stop sequence
+ // call hardStop() rather than finalizeStop() directly because hardStop() checks lifeCycle state and this
+ // avoid running to concurrent stop finalization pieces of code
+ try {
+ hardStop();
+ } catch (InterruptedException e) {
+ LOG.debug("Interrupted while stopping [{}] after process ended", processId.getKey(), e);
+ Thread.currentThread().interrupt();
+ }
}
}
}
}
- @Test
- public void stopForcibly_stops_the_process_without_graceful_request_for_stop() {
- ManagedProcessHandler underTest = newHanderBuilder(A_PROCESS_ID).build();
-
- try (TestManagedProcess testProcess = new TestManagedProcess()) {
- underTest.start(() -> testProcess);
-
- underTest.stopForcibly();
- assertThat(underTest.getState()).isEqualTo(ManagedProcessLifecycle.State.STOPPED);
- assertThat(testProcess.askedForHardStop).isFalse();
- assertThat(testProcess.destroyedForcibly).isTrue();
-
- // second execution of stopForcibly does nothing. It's still stopped.
- underTest.stopForcibly();
- assertThat(underTest.getState()).isEqualTo(ManagedProcessLifecycle.State.STOPPED);
- }
- }
-
@Test
public void process_stops_after_graceful_request_for_stop() throws Exception {
ProcessLifecycleListener listener = mock(ProcessLifecycleListener.class);