Skip to content

fix: event handler listen to ctx.Done - #38

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

GoshaDo merged 5 commits into
mainfrom
event-handler-listen-to-ctx-done

Conversation

@GoshaDo

@GoshaDo GoshaDo commented Jan 9, 2025

Copy link
Copy Markdown
Contributor

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 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
Comment thread pkg/event_handler/main.go
}
}
}
log.Print("[event handler] stopped work, closing watcher")

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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.

@adiludmer adiludmer left a comment

Copy link
Copy Markdown

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
@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