diff --git a/db/active_replicator.go b/db/active_replicator.go index 9845d65c5c..7cae4bfa2c 100644 --- a/db/active_replicator.go +++ b/db/active_replicator.go @@ -208,6 +208,7 @@ func connect(arc *activeReplicatorCommon, idSuffix string) (blipSender *blip.Sen arc.replicationStats.NumConnectAttempts.Add(1) var originPatterns []string // no origin headers for ISGR + // NewSGBlipContext doesn't set cancellation context - active replication cancellation on db close is handled independently blipContext, err := NewSGBlipContext(arc.ctx, arc.config.ID+idSuffix, originPatterns, nil) if err != nil { return nil, nil, err diff --git a/db/database.go b/db/database.go index 2d4821eabc..9106445ad7 100644 --- a/db/database.go +++ b/db/database.go @@ -414,9 +414,13 @@ func NewDatabaseContext(ctx context.Context, dbName string, bucket base.Bucket, UserFunctionTimeout: defaultUserFunctionTimeout, } - // set up cancellable context based on the background context (context lifecycle should decoupled from the request context) - // + // set up cancellable context based on the background context (context lifecycle for the database + // must be distinct from the request context associated with the db create/update). Used to trigger + // teardown of connected replications on database close. dbContext.CancelContext, dbContext.cancelContextFunc = context.WithCancel(context.Background()) + cleanupFunctions = append(cleanupFunctions, func() { + dbContext.cancelContextFunc() + }) // Check if server version supports multi-xattr operations, required for mou handling dbContext.EnableMou = bucket.IsSupported(sgbucket.BucketStoreFeatureMultiXattrSubdocOperations) diff --git a/rest/utilities_testing.go b/rest/utilities_testing.go index dd4fa24fe0..6675831acd 100644 --- a/rest/utilities_testing.go +++ b/rest/utilities_testing.go @@ -1519,7 +1519,8 @@ func createBlipTesterWithSpec(tb testing.TB, spec BlipTesterSpec, rt *RestTester if err != nil { return nil, err } - // Make BLIP/Websocket connection + // Make BLIP/Websocket connection. Not specifying cancellation context here as this is a + // client blip context that doesn't require cancellation-based close bt.blipContext, err = db.NewSGBlipContextWithProtocols(base.TestCtx(tb), "", origin, protocols, nil) if err != nil { return nil, err