mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-25 10:40:02 +08:00
The lifetime of `runPeriodicOperations` was only loosely tied to the lite.Backend via lite.Backend.ctx. When closing the backend the context was cancelled which would eventually terminate `runPeriodicOperations`. However, `lite.Backend.Close` could return while `runPeriodicOperations` was still processing as a result of the periodic ticker firing. To prevent this race the backend now utilizies a sync.WaitGroup to launch `runPeriodicOperations` and waits for the group to be completed _prior_ to returning from `(lite.Backend) Close`. `runPeriodicOperations` also attempted to close the sql.DB when it detected that the context had been cancelled. While the double close is fine due to the idempotence of (lite.Backed) closeDatabase, it was confusing and unnecesarry. Ownership of closing the database now lies exclusively on explicitly calling `(lite.Backend) Close`. The closed flag has also been removed. It existed solely to prevent logging or rolling back transactions that had failed after the underlying database had been closed. Both operations are always attempted now. All logs are silenced in the event that the database is unreachable during process termination. On failure to create the database schema the underlying sqlite database is now closed before returning an error from lite.NewWithConfig.