Skip to content

Commit

Permalink
cmd/atlas/internal/docker: set client conn as ephemeral and limit its…
Browse files Browse the repository at this point in the history
… lifetime
  • Loading branch information
a8m committed Feb 3, 2025
1 parent 6e3b402 commit 3e7fbf3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/atlas/internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ func OpenWithOpts(ctx context.Context, u *url.URL, opts ...ConfigOption) (client
if client, err = sqlclient.Open(ctx, u1.String()); err != nil {
return nil, err
}
client.Ephemeral = true
client.DB.SetConnMaxLifetime(time.Minute)
client.DB.SetConnMaxIdleTime(time.Minute)
client.AddClosers(c)
return client, nil
}
6 changes: 6 additions & 0 deletions sql/sqlclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ type (
schemahcl.Marshaler
schemahcl.Evaluator

// Ephemeral indicates that the database we connect to is "ephemeral"
// (e.g., a temporary running container). This can be set by the driver
// that opens the client to signal to its consumers that there is no need
// to guard against race conditions with other Atlas clients.
Ephemeral bool

// Functions registered by the drivers and used for opening transactions and their clients.
openDriver func(schema.ExecQuerier) (migrate.Driver, error)
openTx TxOpener
Expand Down

0 comments on commit 3e7fbf3

Please sign in to comment.