| 638 | } |
| 639 | |
| 640 | func (context *DatabaseContext) Close(ctx context.Context) { |
| 641 | context.BucketLock.Lock() |
| 642 | defer context.BucketLock.Unlock() |
| 643 | |
| 644 | context.OIDCProviders.Stop() |
| 645 | close(context.terminator) |
| 646 | if context.cancelContextFunc != nil { |
| 647 | context.cancelContextFunc() |
| 648 | } |
| 649 | |
| 650 | // Stop All background processors |
| 651 | bgManagers := context.stopBackgroundManagers() |
| 652 | |
| 653 | // Wait for database background tasks to finish. |
| 654 | waitForBGTCompletion(ctx, BGTCompletionMaxWait, context.backgroundTasks, context.Name) |
| 655 | context.sequences.Stop(ctx) |
| 656 | context._stopOnlineProcesses(ctx) |
| 657 | // Stop the channel cache and its background tasks. |
| 658 | context.channelCache.Stop(ctx) |
| 659 | |
| 660 | waitForBackgroundManagersToStop(ctx, BGTCompletionMaxWait, bgManagers) |
| 661 | |
| 662 | context.Bucket.Close(ctx) |
| 663 | context.Bucket = nil |
| 664 | |
| 665 | base.RemovePerDbStats(context.Name) |
| 666 | |
| 667 | } |
| 668 | |
| 669 | // stopBackgroundManagers stops any running BackgroundManager. |
| 670 | // Returns a list of BackgroundManager it signalled to stop |