@@ -95,8 +95,7 @@ public static final class Runtime {
9595 private volatile boolean quarantined ;
9696
9797 public Runtime (int maxConcurrent ) {
98- this (maxConcurrent , ProcessBuilder ::start , timeoutMillis -> ExecuteWatchdog .builder ()
99- .setTimeout (Duration .ofMillis (timeoutMillis )).get ());
98+ this (maxConcurrent , ProcessBuilder ::start , SubprocessExecutionSupport ::newWatchdog );
10099 }
101100
102101 Runtime (int maxConcurrent , ProcessStarter processStarter , WatchdogFactory watchdogFactory ) {
@@ -120,7 +119,7 @@ public RunSession execute(ExecutionRequest request) throws IOException, Interrup
120119 Process process = null ;
121120 Reader stdoutReader = null ;
122121 Reader stderrReader = null ;
123- ExecuteWatchdog watchdog = watchdogFactory . create ( request . timeoutMillis ) ;
122+ ExecuteWatchdog watchdog = null ;
124123 TerminationReason reason = null ;
125124 IOException ioFailure = null ;
126125 boolean acquired = false ;
@@ -214,7 +213,9 @@ public RunSession execute(ExecutionRequest request) throws IOException, Interrup
214213 } finally {
215214 try {
216215 try {
217- watchdog .stop ();
216+ if (Objects .nonNull (watchdog )) {
217+ watchdog .stop ();
218+ }
218219 } catch (RuntimeException ex ) {
219220 cleanupOperationFailed = true ;
220221 }
@@ -282,12 +283,18 @@ public RunSession execute(ExecutionRequest request) throws IOException, Interrup
282283 .stderrCapturedBytes (err .size ()).stderrObservedBytes (err .observed ()).stderrTruncated (err .isTruncated ())
283284 .elapsedMillis (elapsedMillis (request .submittedAtNanos )).queueWaitMillis (queueWaitMillis )
284285 .descendantsExitConfirmed (false ).build ();
285- return new RunSession (out , err , handler , watchdog , request .timeoutMillis ,
286+ // Preserve the legacy RunSession watchdog view even when nothing was started.
287+ ExecuteWatchdog watchdogView = Objects .nonNull (watchdog ) ? watchdog : newWatchdog (request .timeoutMillis );
288+ return new RunSession (out , err , handler , watchdogView , request .timeoutMillis ,
286289 reason == TerminationReason .QUEUE_TIMEOUT || reason == TerminationReason .EXECUTION_TIMEOUT ,
287290 details , exit , ioFailure );
288291 }
289292 }
290293
294+ private static ExecuteWatchdog newWatchdog (long timeoutMillis ) {
295+ return ExecuteWatchdog .builder ().setTimeout (Duration .ofMillis (timeoutMillis )).get ();
296+ }
297+
291298 private static boolean alive (Thread thread ) { return thread != null && thread .isAlive (); }
292299 private static boolean tryForceStop (Process process ) {
293300 try {
0 commit comments