Skip to content

Ensure that CommitDelayIncrement is greater than TimeSpan.Zero#531

Merged
hazel-bohon merged 6 commits intomainfrom
CommitDelayIncrement_Zero
Mar 4, 2026
Merged

Ensure that CommitDelayIncrement is greater than TimeSpan.Zero#531
hazel-bohon merged 6 commits intomainfrom
CommitDelayIncrement_Zero

Conversation

@hazel-bohon
Copy link
Copy Markdown
Contributor

@hazel-bohon hazel-bohon commented Feb 26, 2026

…t to a negative value in OpenSessionOptions, and add an acceptance test to verify that an exception is thrown to the session user when CommitDelayIncrement is set to zero.
@hazel-bohon hazel-bohon self-assigned this Feb 26, 2026
@hazel-bohon hazel-bohon added the Bug Something isn't working label Feb 26, 2026
@hazel-bohon
Copy link
Copy Markdown
Contributor Author

Some alternatives that reviewers might think about:

  1. Imposing a floor value on the property such as TimeSpan.FromTicks(1) (the absolute minimum value greater than zero), or anything up to the current default of TimeSpan.FromSeconds(2).
  2. Updating this so that it will be able to handle the case where the value is TimeSpan.Zero We could accomplish this by either adding a second check that will cause it to timeout after a certain number of maximum attempts, etc.

Copy link
Copy Markdown

@mnadareski-particular mnadareski-particular left a comment

Choose a reason for hiding this comment

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

The change here directly addresses the issues that were being seen.

I was looking into how and where this value actually ends up being used to see if this fix would be sufficient for any underlying issues. I ran across https://github.com/Particular/NServiceBus/blob/master/src/NServiceBus.Core/DelayedDelivery/DelayDeliveryWith.cs which only checks that it's not less than zero. I'm wondering if other places that cascade out could also have these issues hidden.

Also maybe not relevant for this PR, but I think it would be interesting to see why a duration of 0 was actually causing issues internally.

Edit: After looking at the alternate proposed solution, it makes a lot more sense why the value of 0 would be problematic coming from this context. The point above about DelayDeliveryWith still stands.

Comment thread src/NServiceBus.TransactionalSession/OpenSessionOptions.cs Outdated
Comment thread src/NServiceBus.TransactionalSession.Tests/OpenSessionOptionsTests.cs Outdated
…ests.cs

Co-authored-by: Tamara Rivera <tamita.rivera@gmail.com>
Comment thread src/NServiceBus.TransactionalSession.Tests/OpenSessionOptionsTests.cs Outdated
Copy link
Copy Markdown
Contributor

@danielmarbach danielmarbach left a comment

Choose a reason for hiding this comment

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

Nice find!

Past me thinking: Sure, we can just ship without validation, and it will be fine.

- Syntax fix
- Add unit test for `TimeSpan.FromTicks(1)`
- Update exception to use dotnet library standard interfaces.
@hazel-bohon hazel-bohon mentioned this pull request Mar 4, 2026
@hazel-bohon hazel-bohon merged commit 41b70f7 into main Mar 4, 2026
4 checks passed
@hazel-bohon hazel-bohon deleted the CommitDelayIncrement_Zero branch March 4, 2026 18:22
hazel-bohon added a commit that referenced this pull request Mar 4, 2026
* Throw argument out of range exception when CommitDelayIncrement is set to a negative value in OpenSessionOptions, and add an acceptance test to verify that an exception is thrown to the session user when CommitDelayIncrement is set to zero.


Co-authored-by: Tamara Rivera <tamita.rivera@gmail.com>
hazel-bohon added a commit that referenced this pull request Mar 4, 2026
* Throw argument out of range exception when CommitDelayIncrement is set to a negative value in OpenSessionOptions, and add an acceptance test to verify that an exception is thrown to the session user when CommitDelayIncrement is set to zero.

Co-authored-by: Tamara Rivera <tamita.rivera@gmail.com>
hazel-bohon added a commit that referenced this pull request Mar 9, 2026
* Fix flaky test (#534)

* Add check to ensure that TestMessage is given time to be audited.

* Ensure that CommitDelayIncrement is greater than TimeSpan.Zero (#531)

* Throw argument out of range exception when CommitDelayIncrement is set to a negative value in OpenSessionOptions, and add an acceptance test to verify that an exception is thrown to the session user when CommitDelayIncrement is set to zero.


Co-authored-by: Tamara Rivera <tamita.rivera@gmail.com>

---------

Co-authored-by: Tamara Rivera <tamita.rivera@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If CommitDelayIncrement is set to zero, the Outbox dispatch message the MaximumCommitDuration is never reached

4 participants