Skip to content

Commit fc819d9

Browse files
committed
fix(engine): wait for control containers to finish stopping when DLE shutdowns (#387)
* use contexts without timeout to stop stateful control containers * use a default timeout to stop internal server and stateless auxiliary containers
1 parent 340e5f8 commit fc819d9

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Diff for: engine/cmd/database-lab/main.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ func main() {
126126
emergencyShutdown := func() {
127127
cancel()
128128

129-
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), shutdownTimeout)
130-
defer shutdownCancel()
131-
132-
shutdownDatabaseLabEngine(shutdownCtx, docker, engProps, pm.First())
129+
shutdownDatabaseLabEngine(context.Background(), docker, engProps, pm.First())
133130
}
134131

135132
cloningSvc := cloning.NewBase(&cfg.Cloning, provisioner, tm, observingChan)
@@ -185,16 +182,18 @@ func main() {
185182
<-shutdownCh
186183
cancel()
187184

188-
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), shutdownTimeout)
185+
ctxBackground := context.Background()
186+
187+
shutdownCtx, shutdownCancel := context.WithTimeout(ctxBackground, shutdownTimeout)
189188
defer shutdownCancel()
190189

191190
if err := server.Shutdown(shutdownCtx); err != nil {
192191
log.Msg(err)
193192
}
194193

195-
shutdownDatabaseLabEngine(shutdownCtx, docker, engProps, pm.First())
194+
shutdownDatabaseLabEngine(ctxBackground, docker, engProps, pm.First())
196195
cloningSvc.SaveClonesState()
197-
tm.SendEvent(context.Background(), telemetry.EngineStoppedEvent, telemetry.EngineStopped{Uptime: server.Uptime()})
196+
tm.SendEvent(ctxBackground, telemetry.EngineStoppedEvent, telemetry.EngineStopped{Uptime: server.Uptime()})
198197
}
199198

200199
func getEngineProperties(ctx context.Context, dockerCLI *client.Client, cfg *config.Config) (global.EngineProps, error) {

Diff for: engine/internal/retrieval/engine/postgres/tools/cont/container.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/docker/docker/api/types/container"
1515
"github.com/docker/docker/api/types/filters"
1616
"github.com/docker/docker/client"
17-
"github.com/docker/go-units"
17+
units "github.com/docker/go-units"
1818
"github.com/pkg/errors"
1919

2020
"gitlab.com/postgres-ai/database-lab/v3/internal/provision/pool"
@@ -87,8 +87,6 @@ func StopControlContainers(ctx context.Context, dockerClient *client.Client, ins
8787
if err := tools.StopPostgres(ctx, dockerClient, controlCont.ID, fsm.Pool().DataDir(), tools.DefaultStopTimeout); err != nil {
8888
log.Msg("Failed to stop Postgres", err)
8989
tools.PrintContainerLogs(ctx, dockerClient, controlCont.ID)
90-
91-
continue
9290
}
9391
}
9492

@@ -114,7 +112,11 @@ func CleanUpControlContainers(ctx context.Context, dockerClient *client.Client,
114112
// CleanUpSatelliteContainers removes satellite containers run by Database Lab Engine.
115113
func CleanUpSatelliteContainers(ctx context.Context, dockerClient *client.Client, instanceID string) error {
116114
log.Msg("Clean up satellite containers")
117-
return cleanUpContainers(ctx, dockerClient, instanceID, getSatelliteContainerFilters())
115+
116+
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, StopTimeout)
117+
defer shutdownCancel()
118+
119+
return cleanUpContainers(shutdownCtx, dockerClient, instanceID, getSatelliteContainerFilters())
118120
}
119121

120122
// cleanUpContainers removes containers run by Database Lab Engine.

0 commit comments

Comments
 (0)