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

fix(event): Prevent eventer data races by removing shallow object copy #5139

Merged
merged 1 commit into from
Sep 30, 2024

Conversation

hugoghx
Copy link
Collaborator

@hugoghx hugoghx commented Sep 30, 2024

This issue was surfaced through other changes (PR 5137).

Given that the eventer works in a singleton pattern (see sysEventer global variable), performing this shallow object copy can cause a data race because the copy operation reads the underlying eventer data structures. At the same time, given the global nature of this eventer, other goroutines can be writing to those same data structures.

Since we're already using a singleton pattern in this package, and given that the current copy operation is shallow, copying the object doesn't seem necessary, so this commit changes StandardWriter to build the logAdapter with the e eventer directly instead of copying it.

This issue was surfaced through other changes (PR 5137).

Given that the eventer works in a singleton pattern (see sysEventer
global variable), performing this shallow object copy can cause a data
race because the copy operation reads the underlying eventer data
structures. At the same time, given the global nature of this eventer,
other goroutines can be writing to those same data structures.

Since we're already using a singleton pattern in this package, and given
that the current copy operation is shallow, copying the object doesn't
seem necessary, so this commit changes `StandardWriter` to build the
`logAdapter` with the `e` eventer directly instead of copying it.
@hugoghx hugoghx self-assigned this Sep 30, 2024
@github-actions github-actions bot added the core label Sep 30, 2024
@hugoghx hugoghx added this to the 0.18.x milestone Sep 30, 2024
@hugoghx
Copy link
Collaborator Author

hugoghx commented Sep 30, 2024

Alternatively to this, we could instead guard the copy operation with the existing gatedQueueLock mutex. That would also prevent the data races without removing the copy operation.

Copy link
Collaborator

@jimlambrt jimlambrt left a comment

Choose a reason for hiding this comment

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

ty!

Copy link
Collaborator

@louisruch louisruch left a comment

Choose a reason for hiding this comment

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

going to merge to get release process closer

@louisruch louisruch merged commit 22b54c8 into main Sep 30, 2024
63 of 64 checks passed
@louisruch louisruch deleted the hugo-eventer-no-copy branch September 30, 2024 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants