[dotnet] [bidi] Properly return shared buffer when disposing websocket#16804
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
|
Thank you! |
|
@Piedone you can test it when nightly package (GitHub) will be released. Interesting whether it is proper fix. |
|
I'll check, yep. |
|
|
||
| private readonly ClientWebSocket _webSocket = new(); | ||
| private readonly byte[] _receiveBuffer = ArrayPool<byte>.Shared.Rent(1024 * 8); | ||
| private byte[] _receiveBuffer = ArrayPool<byte>.Shared.Rent(1024 * 8); |
There was a problem hiding this comment.
@RenderMichael @YevgeniyShunevych what if we rent this buffer in the method, and return immediately? At least in this way we can remove finalizer, which brings more complexity.
User description
🔗 Related Issues
Fixes #16801
💥 What does this PR do?
Introduces
Dispose(bool disposing)method to make sure shared buffer returned back to the pool only once.🔄 Types of changes
PR Type
Bug fix
Description
Implements proper IDisposable pattern with Dispose(bool) method
Ensures shared buffer returned to pool only once during disposal
Prevents double-disposal of managed resources
Seals class and nullifies buffer reference after return
Diagram Walkthrough
File Walkthrough
WebSocketTransport.cs
Implement standard IDisposable pattern with proper cleanupdotnet/src/webdriver/BiDi/WebSocketTransport.cs
_receiveBufferfrom readonly to mutable field to allownullification
GC.SuppressFinalize()
unmanaged resource cleanup
return to prevent double-disposal
ReleaseBuffer()