Skip to content

fix: event handler listen to ctx.Done#38

Merged
GoshaDo merged 5 commits intomainfrom
event-handler-listen-to-ctx-done
Jan 16, 2025
Merged

fix: event handler listen to ctx.Done#38
GoshaDo merged 5 commits intomainfrom
event-handler-listen-to-ctx-done

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
This was referenced Feb 12, 2025
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