Skip to content

Commit

Permalink
fix lockups in UpdateStrategyDBMode.HandleEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
randmonkey committed Dec 5, 2024
1 parent afc3beb commit 3fb8cf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions internal/dataplane/sendconfig/dbmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewUpdateStrategyDBModeKonnect(
concurrency int,
diagnostic *diagnostics.ClientDiagnostic,
logger logr.Logger,
) UpdateStrategyDBMode {
) *UpdateStrategyDBMode {
s := NewUpdateStrategyDBMode(client, dumpConfig, version, concurrency, diagnostic, logger)
s.isKonnect = true
return s
Expand Down Expand Up @@ -102,6 +102,7 @@ func (s *UpdateStrategyDBMode) Update(ctx context.Context, targetContent Content
cancel()
s.resourceErrorLock.Lock()
defer s.resourceErrorLock.Unlock()
s.logger.Info("Collecting resource errors")
resourceFailures := resourceErrorsToResourceFailures(s.resourceErrors, s.logger)
if errs != nil {
return mo.None[int](), NewUpdateErrorWithoutResponseBody(
Expand Down Expand Up @@ -159,12 +160,14 @@ func (s *UpdateStrategyDBMode) HandleEvents(
}
}
case <-ctx.Done():
if diagnostic != nil {
// Release resource error lock before sending diffs to diagnositic server to prevent blocking of main procedure of updating.

Check failure on line 163 in internal/dataplane/sendconfig/dbmode.go

View workflow job for this annotation

GitHub Actions / linters / lint

`diagnositic` is a misspelling of `diagnostic` (misspell)
s.resourceErrorLock.Unlock()
// REVIEW: Is there a better way to judge whether dumping diffs enabled than directly checking the channel?
if diagnostic != nil && diagnostic.Diffs != nil {
diff.Timestamp = time.Now().Format(time.RFC3339)
diagnostic.Diffs <- diff
s.logger.V(logging.DebugLevel).Info("recorded database update events and diff", "hash", hash)
}
s.resourceErrorLock.Unlock()
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dataplane/sendconfig/sendconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func PerformUpdate(
updateStrategy := updateStrategyResolver.ResolveUpdateStrategy(client, diagnostic)
logger = logger.WithValues("update_strategy", updateStrategy.Type())
timeStart := time.Now()
err = updateStrategy.Update(ctx, ContentWithHash{
size, err := updateStrategy.Update(ctx, ContentWithHash{
Content: targetContent,
CustomEntities: customEntities,
Hash: newSHA,
Expand Down
1 change: 1 addition & 0 deletions test/kongintegration/dbmode_update_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestUpdateStrategyDBMode(t *testing.T) {
dump.Config{},
semver.MustParse("3.6.0"),
10,
nil,
logger,
)

Expand Down

0 comments on commit 3fb8cf3

Please sign in to comment.