diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-08-06 11:11:32 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-08-06 09:55:49 +0000 |
| commit | 4bd24a3ebf2c0a11349dbd8b6830c5cdf98d2c7d (patch) | |
| tree | 31c1dc5a33351d01f5a022ae12d0bc3c18b079cc /vm | |
| parent | 61ad06c3adc5c20856fd641e634887676f3bf23e (diff) | |
vm/dispatcher: simplify runInstance()
Move boot error reporting to a separate function.
Diffstat (limited to 'vm')
| -rw-r--r-- | vm/dispatcher/pool.go | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/vm/dispatcher/pool.go b/vm/dispatcher/pool.go index d3f937b13..08bc1ebfa 100644 --- a/vm/dispatcher/pool.go +++ b/vm/dispatcher/pool.go @@ -127,18 +127,7 @@ func (p *Pool[T]) runInstance(ctx context.Context, inst *poolInstance[T]) { obj, err := p.creator(inst.idx) if err != nil { - select { - case p.BootErrors <- err: - return - default: - // Print some log message to make it visible. - log.Logf(0, "WARNING: boot error channel is full!") - } - select { - case p.BootErrors <- err: - case <-ctx.Done(): - // On context cancellation, no one might be listening on the channel. - } + p.reportBootError(ctx, err) return } defer obj.Close() @@ -166,6 +155,21 @@ func (p *Pool[T]) runInstance(ctx context.Context, inst *poolInstance[T]) { job(ctx, obj, inst.updateInfo) } +func (p *Pool[T]) reportBootError(ctx context.Context, err error) { + select { + case p.BootErrors <- err: + return + default: + // Print some log message to make it visible. + log.Logf(0, "WARNING: boot error channel is full!") + } + select { + case p.BootErrors <- err: + case <-ctx.Done(): + // On context cancellation, no one might be listening on the channel. + } +} + // ReserveForRun specifies the size of the sub-pool for the execution of custom runners. // The reserved instances will be booted, but the pool will not start the default runner. // To unreserve all instances, execute ReserveForRun(0). |
