Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow handler execution time to exceed the default transaction timeout #661

Merged
merged 8 commits into from Nov 2, 2022

Conversation

danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented Oct 28, 2022

This PR introduces an AzureServiceBusTransportTransaction class that encapsulates the management of the client, partition key and the committable transaction. This allows us to defer the creation of the committable transaction object to the point when we really require it (when dispatching non-isolated dispatches). Due to the lazy creation, the transaction timeout only applies to the point in time when we start dispatching messages and not to the time when we start handling the message. This means the pipeline execution time no longer needs to complete within the transaction timeout and can take as long as Azure Service Bus allows, keeping the message under lock.

During the development of this change I have evaluated several options that would not require Azure Functions integration to be changed but ultimately decided the complexity of the inner workings are not worth it especially considering the fact that Azure Function integration for Azure Service Bus already has a dependency on the transport. On top of that having the transaction public and self-registering in the transport transaction makes the integration point slightly more explicit than just relying on three values being explicitly put into the transport transaction (and one using a magic key).

@ramonsmits
Copy link
Member

Wouldn't it be possible to manage the TX in public async Task Dispatch( and just using an ordinary TransactionScope? I assume Dispatch( isn't called more than once for an incoming message?

@danielmarbach
Copy link
Contributor Author

@ramonsmits Dispatch will be called potentially multiple times. For example, when you have immediate dispatches that will call the dispatcher directly while you still might be collection other non-immediate dispatches.

Also has less closure allocations and doesn't lock
@danielmarbach
Copy link
Contributor Author

I thought I found an elegant approach until I realized the dispatcher still needs to get out the ServiceBusClient, the partition key and the committable transaction. Otherwise, it would break azure functions
https://github.com/Particular/NServiceBus.AzureFunctions.InProcess.ServiceBus/blob/master/src/NServiceBus.AzureFunctions.InProcess.ServiceBus/InProcessFunctionEndpoint.cs#L224-L227

@danielmarbach
Copy link
Contributor Author

Looking at all the test cases and the conditional complexity within the AzureServiceBusTransaction class I'm coming to the conclusion it is better to make that concept public. Functions already references the transport of a given version and they kind of depend on each other. That would be the cleaner approach.

@danielmarbach danielmarbach marked this pull request as ready for review October 31, 2022 11:33
@danielmarbach danielmarbach changed the title Open the committable transaction as late as possible Support for handler execution that takes more than the default transaction timeout Oct 31, 2022
@danielmarbach
Copy link
Contributor Author

@SeanFeldman in case you are curious, I would love to get your input on this one. Of course, I don't want to overload you, so feel free to ignore in case you don't have time.

danielmarbach and others added 2 commits November 1, 2022 17:17
Simplify conditional logic

Co-authored-by: Andreas Bednarz <110360248+abparticular@users.noreply.github.com>
@danielmarbach
Copy link
Contributor Author

Set it to auto-merge since I think I have adressed the comments

@danielmarbach danielmarbach merged commit 61ac320 into master Nov 2, 2022
@danielmarbach danielmarbach deleted the lazy-transaction branch November 2, 2022 09:14
danielmarbach added a commit that referenced this pull request Nov 2, 2022
…ction timeout (#661)

* Open the committable transaction as late as possible

* Custom ReceiveTransaction for better encapsulation
Also has less closure allocations and doesn't lock

* Change approach slightly including some value caching

* TODO for the implementation

* Add tests for all the complex cases

* Simplify approach by making the transaction public

* Adjust transaction handling to expose the base class
Simplify conditional logic

Co-authored-by: Andreas Bednarz <110360248+abparticular@users.noreply.github.com>

* Adjust AzureServiceBusTransportTransaction documentation

Co-authored-by: Andreas Bednarz <110360248+abparticular@users.noreply.github.com>
@danielmarbach danielmarbach added this to the 3.0.0-rc.3 milestone Nov 11, 2022
@danielmarbach danielmarbach changed the title Support for handler execution that takes more than the default transaction timeout Allow handler execution time to exceed the default transaction timeout Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction management for SendsAtomicWithReceive non optimal for long running messages
4 participants