-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[dotnet] [bidi] Properly return shared buffer when disposing websocket #16804
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
[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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()