[fix] Ensure Badger maintenance is stopped before existing Close()#7940
Conversation
Signed-off-by: Yashika0724 <ssyashika1311@gmail.com>
|
Hi @yurishkuro ! Thanks for taking the time to review this. |
| // Close Implements io.Closer and closes the underlying storage | ||
| func (f *Factory) Close() error { | ||
| close(f.maintenanceDone) | ||
| f.bgWg.Wait() // Wait for background goroutines to finish before closing store |
There was a problem hiding this comment.
I can't understand the need! closing the maintenanceDone will close the channel which will close the go routines. How will it lead to race condition? Can you provide the steps for reproducing the race condition or could point to the issue thread
There was a problem hiding this comment.
This is a standard pattern that ensures that goroutines are exiting (i.e. definitely not holding onto any locks or resources) before Close() function exists. This could be helpful in avoiding situations when the process exits while maintenance goroutine still tries to do some writes.
| err := f.store.Close() | ||
|
|
||
| // Remove tmp files if this was ephemeral storage | ||
| if f.Config.Ephemeral { | ||
| errSecondary := os.RemoveAll(f.tmpDir) | ||
| if err == nil { | ||
| err = errSecondary | ||
| } | ||
| } | ||
|
|
||
| return err |
There was a problem hiding this comment.
this could've been simplified to do fewer ifs by using errors.Join()
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7940 +/- ##
==========================================
- Coverage 95.58% 95.55% -0.04%
==========================================
Files 316 316
Lines 16726 16734 +8
==========================================
+ Hits 15988 15990 +2
- Misses 576 580 +4
- Partials 162 164 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Metrics Comparison SummaryTotal changes across all snapshots: 0 Detailed changes per snapshotsummary_metrics_snapshot_cassandra📊 Metrics Diff SummaryTotal Changes: 0
summary_metrics_snapshot_cassandra📊 Metrics Diff SummaryTotal Changes: 0
summary_metrics_snapshot_cassandra📊 Metrics Diff SummaryTotal Changes: 0
summary_metrics_snapshot_cassandra📊 Metrics Diff SummaryTotal Changes: 0
|
|
Related Documentation No published documentation to review for changes on this repository. |
…aegertracing#7940) This PR adds synchronization between the Badger storage factory’s background goroutines and store shutdown. During shutdown (for example, pod termination or process restart), the maintenance or metrics goroutines may still be running while the Badger store is being closed. This change ensures the goroutines are allowed to exit cleanly after shutdown is signaled and before the store is closed. The behavior and APIs remain unchanged; the update only makes the shutdown sequence safer and more predictable. Thanks for taking a look, and please let me know if any adjustments are needed. Signed-off-by: Yashika0724 <ssyashika1311@gmail.com>
…aegertracing#7940) This PR adds synchronization between the Badger storage factory’s background goroutines and store shutdown. During shutdown (for example, pod termination or process restart), the maintenance or metrics goroutines may still be running while the Badger store is being closed. This change ensures the goroutines are allowed to exit cleanly after shutdown is signaled and before the store is closed. The behavior and APIs remain unchanged; the update only makes the shutdown sequence safer and more predictable. Thanks for taking a look, and please let me know if any adjustments are needed. Signed-off-by: Yashika0724 <ssyashika1311@gmail.com>
…aegertracing#7940) This PR adds synchronization between the Badger storage factory’s background goroutines and store shutdown. During shutdown (for example, pod termination or process restart), the maintenance or metrics goroutines may still be running while the Badger store is being closed. This change ensures the goroutines are allowed to exit cleanly after shutdown is signaled and before the store is closed. The behavior and APIs remain unchanged; the update only makes the shutdown sequence safer and more predictable. Thanks for taking a look, and please let me know if any adjustments are needed. Signed-off-by: Yashika0724 <ssyashika1311@gmail.com>
…aegertracing#7940) This PR adds synchronization between the Badger storage factory’s background goroutines and store shutdown. During shutdown (for example, pod termination or process restart), the maintenance or metrics goroutines may still be running while the Badger store is being closed. This change ensures the goroutines are allowed to exit cleanly after shutdown is signaled and before the store is closed. The behavior and APIs remain unchanged; the update only makes the shutdown sequence safer and more predictable. Thanks for taking a look, and please let me know if any adjustments are needed. Signed-off-by: Yashika0724 <ssyashika1311@gmail.com>
This PR adds synchronization between the Badger storage factory’s background goroutines and store shutdown.
During shutdown (for example, pod termination or process restart), the maintenance or metrics goroutines may still be running while the Badger store is being closed. This change ensures the goroutines are allowed to exit cleanly after shutdown is signaled and before the store is closed.
The behavior and APIs remain unchanged; the update only makes the shutdown sequence safer and more predictable.
Thanks for taking a look, and please let me know if any adjustments are needed.