@@ -186,11 +186,7 @@ export interface BootServiceStep {
186186 /** Non-zero exit is logged and ignored. */
187187 readonly optional ?: boolean ;
188188 readonly timeout ?: Duration . Input ;
189- /**
190- * Re-run once a second while the command exits 0, for up to
191- * STOP_STEP_TIMEOUT, until it exits with one of these codes. Any other exit
192- * fails.
193- */
189+ /** Poll successful probes until one of these exits, bounded by STOP_STEP_TIMEOUT. */
194190 readonly untilExit ?: ReadonlyArray < number > ;
195191}
196192
@@ -300,10 +296,8 @@ function launchdManager(input: {
300296 ) ;
301297 const domainTarget = `gui/${ input . uid } ` ;
302298 const serviceTarget = `${ domainTarget } /${ BOOT_SERVICE_LAUNCHD_LABEL } ` ;
303- // bootout returns while the job drains for up to ExitTimeOut, and a
304- // bootstrap during the drain fails EIO. `print` finds the job until launchd
305- // has removed it: 113 is no such service, 112 no such domain. The wait is
306- // strict, so a bootout that failed with the job still loaded fails here.
299+ // bootout returns before draining finishes; bootstrap races fail EIO until print reports
300+ // no such service (113) or domain (112). Other failures must not permit bootstrap.
307301 const waitForStop : BootServiceStep = {
308302 step : "waiting for the launch agent to stop" ,
309303 command : "launchctl" ,
@@ -631,39 +625,26 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
631625 step : string ,
632626 command : string ,
633627 args : ReadonlyArray < string > ,
634- options ?: { readonly timeout ?: Duration . Input } ,
628+ options ?: Pick < BootServiceStep , " timeout" | "untilExit" > ,
635629 ) {
636- return yield * runner . run ( { command, args, timeout : options ?. timeout } ) . pipe (
630+ const untilExit = options ?. untilExit ;
631+ const commandRun = runner . run ( { command, args, timeout : options ?. timeout } ) ;
632+ const run =
633+ untilExit === undefined
634+ ? commandRun
635+ : commandRun . pipe (
636+ Effect . repeat ( {
637+ schedule : Schedule . spaced ( Duration . seconds ( 1 ) ) ,
638+ while : ( result ) => result . code === 0 ,
639+ } ) ,
640+ Effect . timeout ( STOP_STEP_TIMEOUT ) ,
641+ Effect . withSpan ( "cloud.boot_service.wait_for_step" ) ,
642+ ) ;
643+ return yield * run . pipe (
637644 Effect . mapError ( ( cause ) => new BootServiceCommandError ( { step, cause } ) ) ,
638645 Effect . filterOrFail (
639- ( result ) => result . code === 0 ,
640646 ( result ) =>
641- new BootServiceCommandError ( {
642- step,
643- exitCode : Number ( result . code ) ,
644- stdoutLength : result . stdout . length ,
645- stderrLength : result . stderr . length ,
646- } ) ,
647- ) ,
648- Effect . tapError ( logFailure ) ,
649- ) ;
650- } ) ;
651-
652- const waitForStep = Effect . fn ( "cloud.boot_service.wait_for_step" ) ( function * (
653- step : string ,
654- command : string ,
655- args : ReadonlyArray < string > ,
656- untilExit : ReadonlyArray < number > ,
657- ) {
658- return yield * runner . run ( { command, args } ) . pipe (
659- Effect . repeat ( {
660- schedule : Schedule . spaced ( Duration . seconds ( 1 ) ) ,
661- while : ( result ) => result . code === 0 ,
662- } ) ,
663- Effect . timeout ( STOP_STEP_TIMEOUT ) ,
664- Effect . mapError ( ( cause ) => new BootServiceCommandError ( { step, cause } ) ) ,
665- Effect . filterOrFail (
666- ( result ) => untilExit . includes ( Number ( result . code ) ) ,
647+ untilExit === undefined ? result . code === 0 : untilExit . includes ( Number ( result . code ) ) ,
667648 ( result ) =>
668649 new BootServiceCommandError ( {
669650 step,
@@ -680,15 +661,7 @@ export const make = Effect.fn("cloud.boot_service.make")(function* (input: {
680661 Effect . forEach (
681662 steps ,
682663 ( entry ) => {
683- const run =
684- entry . untilExit === undefined
685- ? runStep (
686- entry . step ,
687- entry . command ,
688- entry . args ,
689- entry . timeout === undefined ? undefined : { timeout : entry . timeout } ,
690- )
691- : waitForStep ( entry . step , entry . command , entry . args , entry . untilExit ) ;
664+ const run = runStep ( entry . step , entry . command , entry . args , entry ) ;
692665 return entry . optional === true ? run . pipe ( Effect . ignore ) : run . pipe ( Effect . asVoid ) ;
693666 } ,
694667 { discard : true } ,
0 commit comments