Skip to content

Commit e29ee24

Browse files
authored
fix: fdv2 datasystem leaves sychronizer open after client is closed (#337)
**Requirements** - [ ] I have added test coverage for new or changed functionality - [x] I have followed the repository's [pull request submission guidelines](../blob/v5/CONTRIBUTING.md#submitting-pull-requests) - [x] I have validated my changes against all supported platform versions **Describe the solution you've provided** This update modifies the runSynchronizers method to ensure that both primary and secondary synchronizers are closed before returning due to a client shutdown. **Describe alternatives you've considered** Alternatively, we could handle the context cancelling in the synchronizer implementation, but this is a less disruptive change. **Additional context** Take a look at jira issue for a more detailed investigation of the problem <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Always close primary and secondary synchronizers after processing results, even when context is canceled, to avoid leaving them open after client shutdown. > > - **FDv2 DataSystem (`internal/datasystem/fdv2_datasystem.go`)**: > - Ensure `primarySync.Close()` and `secondarySync.Close()` are invoked immediately after `consumeSynchronizerResults`, before checking for `context.Canceled`. > - Prevents leaving synchronizers running by closing them unconditionally after each sync cycle. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5a76595. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent bd72e1d commit e29ee24

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/datasystem/fdv2_datasystem.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,12 @@ func (f *FDv2) runSynchronizers(ctx context.Context, closeWhenReady chan struct{
288288
f.loggers.Debugf("Primary synchronizer %s is starting", primarySync.Name())
289289
resultChan := primarySync.Sync(f.store)
290290
removeSync, fallbackv1, err := f.consumeSynchronizerResults(ctx, resultChan, f.fallbackCond, closeWhenReady)
291+
292+
if err := primarySync.Close(); err != nil {
293+
f.loggers.Errorf("Primary synchronizer %s failed to gracefully close: %v", primarySync.Name(), err)
294+
}
291295
if errors.Is(err, context.Canceled) {
292296
return
293-
} else if err := primarySync.Close(); err != nil {
294-
f.loggers.Errorf("Primary synchronizer %s failed to gracefully close: %v", primarySync.Name(), err)
295297
}
296298

297299
if removeSync {
@@ -327,10 +329,12 @@ func (f *FDv2) runSynchronizers(ctx context.Context, closeWhenReady chan struct{
327329

328330
resultChan = secondarySync.Sync(f.store)
329331
removeSync, fallbackv1, err = f.consumeSynchronizerResults(ctx, resultChan, f.recoveryCond, closeWhenReady)
332+
333+
if err := secondarySync.Close(); err != nil {
334+
f.loggers.Errorf("Secondary synchronizer %s failed to gracefully close: %v", secondarySync.Name(), err)
335+
}
330336
if errors.Is(err, context.Canceled) {
331337
return
332-
} else if err := secondarySync.Close(); err != nil {
333-
f.loggers.Errorf("Secondary synchronizer %s failed to gracefully close: %v", secondarySync.Name(), err)
334338
}
335339

336340
if removeSync {

0 commit comments

Comments
 (0)