Open
Conversation
… oversized-response tests on net462 Agent-Logs-Url: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/sessions/7bf71274-9739-427f-9169-7f035cb1a946 Co-authored-by: martincostello <1439341+martincostello@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix flakiness in WsTransport_DropsOversizedResponse test
fix(opamp): remove flakiness in oversized WebSocket response tests on net462
Apr 21, 2026
martincostello
approved these changes
Apr 21, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4169 +/- ##
==========================================
+ Coverage 73.66% 73.80% +0.14%
==========================================
Files 466 458 -8
Lines 18330 18288 -42
==========================================
- Hits 13502 13498 -4
+ Misses 4828 4790 -38
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Stabilizes OpAmp WebSocket oversized-response tests on .NET Framework (net462) by tolerating a known race where the transport aborts the socket while a client SendAsync is still in-flight.
Changes:
- Wrap
wsTransport.SendAsync(...)withRecord.ExceptionAsyncin two oversized-response tests. - Treat
null,WebSocketException, andOperationCanceledExceptionas acceptable outcomes for the send in these scenarios while preserving all existing close-status and “no frames dispatched” assertions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
On .NET Framework (net462), the WebSocket receive loop can abort/close the socket while
SendAsyncis still in-flight after detecting an oversized server message. This races to produce aWebSocketException("transitioned into 'Aborted' state") orOperationCanceledExceptionthat the tests did not tolerate, causing intermittent failures.Changes
WsTransport_DropsOversizedResponseWithoutDispatchingFrame— wrapSendAsyncwithRecord.ExceptionAsync; assert the exception isnull,WebSocketException, orOperationCanceledException(any other type fails the test)WsTransport_LogsOversizedResponseWarning— same fix; identical pattern with the same race exposureAll original assertions are preserved: server closes with
MessageTooBig, no frames dispatched to listeners.No production code changed.
Original prompt
Repo: open-telemetry/opentelemetry-dotnet-contrib
Failing CI job URL: https://github.com/open-telemetry/opentelemetry-dotnet-contrib/actions/runs/24716677111/job/72294849492
Failure:
Goal:
Implementation guidance:
WsTransport_DropsOversizedResponseWithoutDispatchingFrameintest/OpenTelemetry.OpAmp.Client.Tests/WsTransportTest.cs.await wsTransport.SendAsync(...)call withRecord.ExceptionAsync(or Assert.ThrowsAnyAsync if preferred), and allowWebSocketException(and optionallyOperationCanceledException) as acceptable outcomes. Fail if any other exception occurs.TryGetClientCloseStatuswithin 5 seconds and status equalsWebSocketCloseStatus.MessageTooBigmockListenerreceives no messageFiles involved:
Notes:
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The failing job is due to a flaky/incorrect expectation in
WsTransport_DropsOversizedResponseWithoutDispatchingFramewhen running on .NET Framework (net462).What’s happening
The test sends a request (
wsTransport.SendAsync(...)) and then asserts the server observed the client closing withMessageTooBig:System.Net.WebSockets.WebSocketException: ... transitioned into the 'Aborted' statesrc/OpenTelemetry.OpAmp.Client/Internal/Transport/WebSocket/WsTransmitter.cs:40and is surfaced by the test at:
test/OpenTelemetry.OpAmp.Client.Tests/WsTransportTest.cs:250This indicates the receive loop likely detects the oversized server response and closes/aborts the socket while the client send is still in-flight, which on net462 can surface as an
AbortedWebSocket and causeSendAsyncto throw. The test currently doesn’t allow for that race.Solution (make the test resilient to the expected abort)
Update
WsTransport_DropsOversizedResponseWithoutDispatchingFrameto tolerate aWebSocketException(and/orOperationCanceledException) fromSendAsync, because aborting the socket is an acceptable outcome once an oversized message is received.Suggested test change
In
test/OpenTelemetry.OpAmp.Client.Tests/WsTransportTest.cs, modify theSendAsyncline to record/ignore the expected exception:This keeps the intent of the test (oversized response is dropped, no frame dispatched, connection closed with
MessageTooBig) while removing the timing dependency that causes the net462 abort.Optional hardening (library-side)
If you want the client API to behave more predictably, you can also consider handling “socket already aborted/closed...
This pull request was created from Copilot chat.