Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: make sure interactive containers are released on disconnect #3025

Merged
merged 1 commit into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/gateway/container.go
Expand Up @@ -361,6 +361,8 @@ func (gwCtr *gatewayContainer) Start(ctx context.Context, req client.StartReques
}

func (gwCtr *gatewayContainer) Release(ctx context.Context) error {
gwCtr.mu.Lock()
defer gwCtr.mu.Unlock()
gwCtr.cancel()
err1 := gwCtr.errGroup.Wait()

Expand All @@ -371,6 +373,7 @@ func (gwCtr *gatewayContainer) Release(ctx context.Context) error {
err2 = err
}
}
gwCtr.cleanup = nil

if err1 != nil {
return stack.Enable(err1)
Expand Down
6 changes: 6 additions & 0 deletions frontend/gateway/forwarder/forward.go
Expand Up @@ -50,6 +50,7 @@ type bridgeClient struct {
workers worker.Infos
workerRefByID map[string]*worker.WorkerRef
buildOpts client.BuildOpts
ctrs []client.Container
}

func (c *bridgeClient) Solve(ctx context.Context, req client.SolveRequest) (*client.Result, error) {
Expand Down Expand Up @@ -208,6 +209,10 @@ func (c *bridgeClient) toFrontendResult(r *client.Result) (*frontend.Result, err
}

func (c *bridgeClient) discard(err error) {
for _, ctr := range c.ctrs {
ctr.Release(context.TODO())
}

for id, workerRef := range c.workerRefByID {
workerRef.ImmutableRef.Release(context.TODO())
delete(c.workerRefByID, id)
Expand Down Expand Up @@ -299,6 +304,7 @@ func (c *bridgeClient) NewContainer(ctx context.Context, req client.NewContainer
if err != nil {
return nil, err
}
c.ctrs = append(c.ctrs, ctr)
return ctr, nil
}

Expand Down
7 changes: 7 additions & 0 deletions frontend/gateway/gateway.go
Expand Up @@ -345,6 +345,13 @@ func (b *bindMount) IdentityMapping() *idtools.IdentityMapping {
func (lbf *llbBridgeForwarder) Discard() {
lbf.mu.Lock()
defer lbf.mu.Unlock()

for ctr := range lbf.ctrs {
lbf.ReleaseContainer(context.TODO(), &pb.ReleaseContainerRequest{
ContainerID: ctr,
})
}

for id, workerRef := range lbf.workerRefByID {
workerRef.ImmutableRef.Release(context.TODO())
delete(lbf.workerRefByID, id)
Expand Down