Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,10 @@ func (c *mongoClient) GetCollection(dbName, col string) StoreCollection {
func (c *mongoClient) HealthCheck(ctx context.Context) error {
return c.client.Ping(ctx, nil)
}

// Close disconnects the underlying MongoDB driver client, releasing its
// connection pool. Implements io.Closer so callers can type-assert
// StoreClient to io.Closer for graceful shutdown.
func (c *mongoClient) Close() error {
return c.client.Disconnect(context.Background())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add a deadline when disconnecting Mongo client

Close() calls Disconnect(context.Background()), but Mongo driver's Disconnect waits for in-use connections to be returned and only stops waiting when the context is canceled/deadlined. In shutdown paths with a stuck/leaked DB operation, this can block indefinitely and prevent graceful process termination; using a bounded timeout context inside Close() avoids hanging services while still releasing the pool in normal cases.

Useful? React with 👍 / 👎.

}