mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 20:17:09 +00:00
fix(ioscompanion): spawn companion under driver-lifetime context
This commit is contained in:
1 parent
29b5752e44
commit
8fb7dd9f89
1 file changed
+12
-1
@@ -101,6 +101,13 @@ type Driver struct {
|
|||||||
spawnChild func(ctx context.Context, address string) (*exec.Cmd, error)
|
spawnChild func(ctx context.Context, address string) (*exec.Cmd, error)
|
||||||
dial func(address string) (transport.Companion, error)
|
dial func(address string) (transport.Companion, error)
|
||||||
child *exec.Cmd
|
child *exec.Cmd
|
||||||
|
|
||||||
|
// processContext owns the companion child's lifetime: it is derived from
|
||||||
|
// New's context (so a canceled run still reaps the child) and canceled by
|
||||||
|
// Close. Spawning under a startup-scoped context would SIGTERM the child
|
||||||
|
// the moment startup finishes.
|
||||||
|
processContext context.Context
|
||||||
|
processCancel context.CancelFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// New extracts the embedded companion, spawns it against the configured
|
// New extracts the embedded companion, spawns it against the configured
|
||||||
@@ -146,6 +153,7 @@ func New(ctx context.Context, options Options) (*Driver, error) {
|
|||||||
driverInstance.address = address
|
driverInstance.address = address
|
||||||
driverInstance.restart = driverInstance.respawnAndRedial
|
driverInstance.restart = driverInstance.respawnAndRedial
|
||||||
driverInstance.resetContainer = driverInstance.resetDataContainer
|
driverInstance.resetContainer = driverInstance.resetDataContainer
|
||||||
|
driverInstance.processContext, driverInstance.processCancel = context.WithCancel(ctx)
|
||||||
|
|
||||||
if err := driverInstance.bringUp(ctx); err != nil {
|
if err := driverInstance.bringUp(ctx); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -167,7 +175,7 @@ func (d *Driver) bringUp(ctx context.Context) error {
|
|||||||
startupCtx, cancel := context.WithTimeout(ctx, startupTimeout)
|
startupCtx, cancel := context.WithTimeout(ctx, startupTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
child, err := d.spawnChild(startupCtx, d.address)
|
child, err := d.spawnChild(d.processContext, d.address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("spawn companion: %w", err)
|
return fmt.Errorf("spawn companion: %w", err)
|
||||||
}
|
}
|
||||||
@@ -629,6 +637,9 @@ func (d *Driver) Close() {
|
|||||||
d.companion = nil
|
d.companion = nil
|
||||||
}
|
}
|
||||||
d.stopChild()
|
d.stopChild()
|
||||||
|
if d.processCancel != nil {
|
||||||
|
d.processCancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stopChild terminates the companion child gracefully (SIGTERM, grace window,
|
// stopChild terminates the companion child gracefully (SIGTERM, grace window,
|
||||||
|
|||||||
Reference in new issue
Block a user