azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[ServiceBus] Buffer receive bodies
Builds on top of #31214
This brings back an approach discussed in https://github.com/Azure/azure-sdk-for-net/pull/20320 but with a twist to address the scenario that it is possible to hold on to ServiceBusReceivedMessage for longer than the lifetime of the processor callbacks. This is a hack to demonstrate the idea. Like discussed previously this could also be an opt-in feature exposed over the options.
This should also address the fact that Annotated Messages are mutable and the body can be exchanged. Once the body is replaced, it will get GCed and then the buffer is released by the finalizer.
Not immediately returning buffers should not be an issue according to the ArrayPool documentation. Alternatively, it would also be possible to expose an array pool over the options so that a different one can be used for the received messages.
Failure to return a rented buffer is not a fatal error. However, it may lead to decreased application performance, as the pool may need to create a new buffer to replace the lost one.
https://learn.microsoft.com/en-us/dotnet/api/system.buffers.arraypool-1.rent?view=net-6.0#System_Buffers_ArrayPool_1_Rent_System_Int32_
Let's discuss and shoot it down ;)
Contributing to the Azure SDK
Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.
For specific information about pull request etiquette and best practices, see this section.
Thank you for your contribution @danielmarbach! We will review the pull request and get back to you soon.
If only we had a way that we could observe a value in the weak table going out of scope and use that to deterministically tell the key to return the buffer.
@jsquire it would only work by manually managing things via WeakReference and then having a cleanup thread periodically going through the tracked weak references, freeing the buffers of the ones that are no longer alive. So, essentially rebuilding parts of ConditionalWeakTable and finalizer of GC with manual infrastructure.
Hi @danielmarbach. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.
Closing this with a sad face :crying_cat_face: based on this comment