You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ICapPublisher.PublishDelayAsync method in the .NET Core CAP library exhibits thread-safety and cancellation handling issues when the delay time is less than 1 minute. These issues can lead to silent failures and message accumulation in the database.
Detailed Problems
Thread-safety Issue:
The Dispatcher.EnqueueToScheduler method uses a non-thread-safe PriorityQueue to manage delayed messages.
Under race conditions, the PriorityQueue can return null messages.
This causes the fire-and-forget task (Dispatcher: line 80) to fail silently, with no error logging.
As a result, delayed message processing halts, and future scheduled messages are not sent until the application restarts.
Cancellation Handling Issue:
The _delayCts cancellation token is initialized only once.
Once _delayCts is cancelled, subsequent calls to await Task.Delay(new TimeSpan(delayTime), _delayCts.Token) throw an OperationCanceledException.
The exception is ignored in the catch block, leading to a while (TryPeek) loop that spins continuously until the delay time expires.
Consequences of Silent Failures:
Delayed messages continue to accumulate in the database without being processed.
Upon application restart, querying delayed messages without a limit causes the database to timeout.
Manual intervention is required to delete unprocessed messages and restore application functionality.
Steps to Reproduce
Call ICapPublisher.PublishDelayAsync concurrently with delay times less than 1 minute.
Observe that:
Some messages are not processed.
Future scheduled messages are not sent.
I have fixed the above problems while maintaining existing functionality as closely as possible. I will open a pull request with tests and code changes to address the issue.
The text was updated successfully, but these errors were encountered:
Version: 8.3.2
Problem Summary
The
ICapPublisher.PublishDelayAsync
method in the .NET Core CAP library exhibits thread-safety and cancellation handling issues when the delay time is less than 1 minute. These issues can lead to silent failures and message accumulation in the database.Detailed Problems
Thread-safety Issue:
Dispatcher.EnqueueToScheduler
method uses a non-thread-safePriorityQueue
to manage delayed messages.PriorityQueue
can returnnull
messages.Cancellation Handling Issue:
_delayCts
cancellation token is initialized only once._delayCts
is cancelled, subsequent calls toawait Task.Delay(new TimeSpan(delayTime), _delayCts.Token)
throw anOperationCanceledException
.catch
block, leading to awhile (TryPeek)
loop that spins continuously until the delay time expires.Consequences of Silent Failures:
Steps to Reproduce
ICapPublisher.PublishDelayAsync
concurrently with delay times less than 1 minute.I have fixed the above problems while maintaining existing functionality as closely as possible. I will open a pull request with tests and code changes to address the issue.
The text was updated successfully, but these errors were encountered: