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 handler listen to ctx.Done #38

Merged
merged 5 commits into from
Jan 16, 2025

Conversation

GoshaDo
Copy link
Contributor

@GoshaDo GoshaDo commented Jan 9, 2025

Pull Request

Description

Possible race condition on watcher.Stop() and stop()
Added listen to closure of watcher channel and stop the program

Before submitting this pull request, please ensure that you have completed the following tasks:

@GoshaDo GoshaDo requested a review from omri2001 January 11, 2025 15:27
@GoshaDo GoshaDo force-pushed the event-handler-listen-to-ctx-done branch from f90f747 to b285804 Compare January 11, 2025 15:29
@GoshaDo GoshaDo force-pushed the event-handler-listen-to-ctx-done branch from b285804 to 399a7e6 Compare January 11, 2025 16:26
}
}
log.Print("[event handler] stopped work, closing watcher")

Choose a reason for hiding this comment

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

@GoshaDo can explain how the race condition could happen ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If stop() is called, it will cancel the context (ctx). If the context is already canceled before watcher.Stop() completes, there could be race conditions or unexpected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok there are no race condition, but it is a good practice to stop the process if the watcher Chanel closed.

Copy link

@adiludmer adiludmer left a comment

Choose a reason for hiding this comment

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

see comment

@GoshaDo GoshaDo requested a review from adiludmer January 11, 2025 18:14
@GoshaDo GoshaDo merged commit 9a36417 into main Jan 16, 2025
7 checks passed
@GoshaDo GoshaDo deleted the event-handler-listen-to-ctx-done branch January 16, 2025 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants