Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Improve handling of global and local mutexes to mitigate capture deadlocks #335

Merged
merged 4 commits into from
Jul 14, 2024

Conversation

fako1024
Copy link
Collaborator

@fako1024 fako1024 commented Jul 11, 2024

Closes #334

@fako1024 fako1024 added bug Something isn't working feature New feature or request critical Issues that should be looked at with priority labels Jul 11, 2024
@fako1024 fako1024 requested a review from els0r July 11, 2024 08:41
@fako1024 fako1024 self-assigned this Jul 11, 2024
@fako1024 fako1024 linked an issue Jul 11, 2024 that may be closed by this pull request
3 tasks
@@ -44,57 +44,6 @@ var (
// providing the ability to override the default behavior, e.g. in mock tests
type sourceInitFn func(*Capture) (Source, error)

// Captures denotes a named set of Capture instances, wrapping a map and the
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just cleanup, moved to new file captures.go below...

@@ -515,6 +519,10 @@ func (cm *Manager) rotate(ctx context.Context, writeoutChan chan<- capturetypes.
// Lock the running capture in order to safely perform rotation tasks
if err := mc.capLock.Lock(); err != nil {
logger.Errorf("failed to establish rotation three-point lock: %s", err)
if err := mc.close(); err != nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing (I think because I was worried that we might end up with duplicate calls to close(). However, this is now reasonably safe due to the additional capture Mutex.

@@ -560,17 +572,17 @@ func (cm *Manager) logErrors(ctx context.Context, iface string, errsChan <-chan

// Ensure there is no conflict with calls to update() that might already be
// taking down this interface
cm.Lock()
defer cm.Unlock()
cm.captures.Lock()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tiny detail, but important. We lock the set of captures (because that's the only thin we potentially manipulate here) instead of the whole manager.

@fako1024 fako1024 changed the title Improve handling of global and local locks to mitigate capture deadlocks [bugifx] Improve handling of global and local mutexes to mitigate capture deadlocks Jul 11, 2024
@fako1024 fako1024 changed the title [bugifx] Improve handling of global and local mutexes to mitigate capture deadlocks [bugfix] Improve handling of global and local mutexes to mitigate capture deadlocks Jul 11, 2024
@fako1024 fako1024 merged commit 4e21ce4 into main Jul 14, 2024
6 checks passed
@fako1024 fako1024 deleted the 334-improve-resilience-against-capture-deadlocks branch July 14, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical Issues that should be looked at with priority feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve resilience against capture deadlocks
2 participants