Conversation
…Registry.cs, MiniCronTests.EventInvocationOutsideLock.cs Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
…variables, and redundant null checks Co-authored-by: jeanlrnt <63308635+jeanlrnt@users.noreply.github.com>
Refactor: Invoke JobRegistry events outside WriteLock to prevent blocking and deadlocks
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the JobRegistry class to invoke events (JobAdded, JobRemoved, JobUpdated) outside of write locks, improving concurrency by allowing read operations to proceed while event handlers are executing. This prevents long-running event handlers from blocking registry operations.
Key changes:
- Event invocations moved outside write locks in
ScheduleJob,RemoveJob, andUpdateSchedulemethods - Event arguments are prepared inside the lock, then events are invoked after releasing the lock
- Documentation updated to reflect that events are now "raised after the write lock is released"
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/MiniCron.Core/Services/JobRegistry.cs |
Refactored all three registry modification methods to prepare event arguments within the write lock, then invoke events outside the lock; updated XML documentation to reflect the new behavior |
src/MiniCron.Tests/MiniCronTests.EventInvocationOutsideLock.cs |
Added comprehensive test suite verifying events are invoked outside locks, allowing concurrent reads, handling exceptions gracefully, preventing deadlocks on reentrant calls, and validating event argument correctness |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.