mirror of
https://github.com/moby/buildkit.git
synced 2026-08-08 16:50:44 +00:00
Bind session RPC contexts to caller lifetime so ongoing RPCs fail when the session is canceled. Add an integration test that blocks the session tunnel and verifies the health monitor releases the hung build after timeout. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
18 lines
463 B
Go
18 lines
463 B
Go
package session
|
|
|
|
import "context"
|
|
|
|
// contextWithCaller returns a context that is canceled when either the request
|
|
// context is done or the session context is closed.
|
|
func contextWithCaller(ctx context.Context, callerCtx context.Context) context.Context {
|
|
ctx, cancel := context.WithCancelCause(ctx)
|
|
context.AfterFunc(callerCtx, func() {
|
|
cause := context.Cause(callerCtx)
|
|
if cause == nil {
|
|
cause = context.Canceled
|
|
}
|
|
cancel(cause)
|
|
})
|
|
return ctx
|
|
}
|