You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
• Fix issue where Selenium 2.48 doesn't trigger JavaScript in link's href on click()
• Ensure JavaScript in href attributes is properly executed when clicking links in Firefox 42.0
• Fix "ConnectFailure (Connection refused)" errors when instantiating ChromeDriver multiple times
• Address issues with ChromeDriver 2.35 on Ubuntu 16.04.4 with Chrome 65.0.3325.181
The shared memory stream position isn't reset before calling ToArray(), which will return the entire buffer including any previously written data. Reset the position to 0 before calling ToArray().
public async Task<byte[]> ReceiveAsync(CancellationToken cancellationToken)
{
_sharedMemoryStream.SetLength(0);
WebSocketReceiveResult result;
do
{
result = await _webSocket.ReceiveAsync(_receiveBuffer, cancellationToken).ConfigureAwait(false);
await _sharedMemoryStream.WriteAsync(_receiveBuffer.Array!, _receiveBuffer.Offset, result.Count, cancellationToken).ConfigureAwait(false);
}
while (!result.EndOfMessage);
+ _sharedMemoryStream.Position = 0;
byte[] data = _sharedMemoryStream.ToArray();
Apply this suggestion
Suggestion importance[1-10]: 9
__
Why: This is a critical bug fix. Without resetting the stream position to 0 before calling ToArray(), the method would return the entire buffer including any previously written data, potentially causing data corruption. The PR removed the previous Seek(0, SeekOrigin.Begin) call when switching to a shared memory stream.
High
Learned best practice
Replace null-forgiving operators with proper null checks to prevent potential NullReferenceExceptions
The code uses a null-forgiving operator (!) on _receiveBuffer.Array, which assumes the array is never null. Instead, add a proper null check or use null-conditional operators to safely handle potentially null values and prevent NullReferenceExceptions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
🔗 Related Issues
💥 What does this PR do?
Improve memory allocation.
🔧 Implementation Notes
💡 Additional Considerations
🔄 Types of changes
PR Type
Enhancement, Bug fix
Description
Reused a shared
MemoryStreamto optimize memory allocation.Updated
ReceiveAsyncto use the shared memory stream.Improved semaphore handling in
SendAsyncfor better performance.Added proper disposal of shared resources in
Disposemethod.Changes walkthrough 📝
WebSocketTransport.cs
Optimize memory and resource management in WebSocketTransportdotnet/src/webdriver/BiDi/Communication/Transport/WebSocketTransport.cs
MemoryStreamfor memory reuse.ReceiveAsyncto use the shared memory stream.SendAsync.Dispose.