Skip to content

Fix TcpSpec.Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely race condition on Linux - #7815

Merged
Aaronontheweb merged 2 commits into
akkadotnet:devfrom
Aaronontheweb:fix/tcp-abort-race-condition-linux
Sep 9, 2025
Merged

Aaronontheweb merged 2 commits into
akkadotnet:devfrom
Aaronontheweb:fix/tcp-abort-race-condition-linux

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Problem

The test Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely was failing intermittently on Linux due to platform-specific TCP behavior. This issue caused 11 failed attempts in PR #7813.

Root Cause

Linux requires active recv() calls to detect TCP RST during connection establishment.

  • Linux: RST detection depends on active socket reading
  • Windows: More aggressive RST detection works automatically
  • Test was creating "zombie" connections (established but not actively reading)
  • When abort happened before active reading, RST detection failed on Linux

Solution

  1. Wait for TCP connection establishment: Use ViaMaterialized(..., Keep.Right) to ensure connection is fully ready
  2. Start active reading: Add readSub.Request(1) to trigger recv() calls on Linux
  3. Then abort: RST detection now works reliably across platforms

This makes the test behave like real applications that immediately start using their TCP connections.

Testing

  • ✅ Test passes consistently on multiple runs
  • ✅ All TCP tests still pass (19 passed, 3 skipped)
  • ✅ Works on both .NET Framework 4.8 and .NET 8.0

Files Changed

  • src/core/Akka.Streams.Tests/IO/TcpSpec.cs - Updated test to wait for connection and start reading

Closes #7813

The test 'Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely'
was failing intermittently on Linux due to platform-specific TCP behavior.

Root cause:
- Linux requires active recv() calls to detect TCP RST during connection establishment
- Test was creating "zombie" connections (established but not actively reading)
- When abort happened before active reading, RST detection failed on Linux
- Windows worked fine due to more aggressive RST detection

Solution:
1. Wait for TCP connection to be fully established using ViaMaterialized
2. Start active reading with readSub.Request(1) to trigger recv() on Linux
3. Then abort - ensuring RST detection works reliably across platforms

This makes the test behave like real applications that immediately start
using their TCP connections, which is why real apps don't have this issue.

Fixes the race condition that caused 11 failed attempts in PR akkadotnet#7813.
@Aaronontheweb Aaronontheweb changed the title Fix race condition in TCP abort test for Linux compatibility Fix TcpSpec.Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely race condition on Linux Sep 9, 2025
@Aaronontheweb Aaronontheweb changed the title Fix TcpSpec.Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely race condition on Linux Fix TcpSpec.Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely race condition on Linux Sep 9, 2025
@Aaronontheweb
Aaronontheweb enabled auto-merge (squash) September 9, 2025 17:32
@Aaronontheweb
Aaronontheweb enabled auto-merge (squash) September 9, 2025 17:33
@Aaronontheweb
Aaronontheweb merged commit 6aee8bd into akkadotnet:dev Sep 9, 2025
11 checks passed
@Aaronontheweb
Aaronontheweb deleted the fix/tcp-abort-race-condition-linux branch September 9, 2025 17:38
Aaronontheweb added a commit that referenced this pull request Jul 2, 2026
The test 'Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely'
was failing intermittently on Linux due to platform-specific TCP behavior.

Root cause:
- Linux requires active recv() calls to detect TCP RST during connection establishment
- Test was creating "zombie" connections (established but not actively reading)
- When abort happened before active reading, RST detection failed on Linux
- Windows worked fine due to more aggressive RST detection

Solution:
1. Wait for TCP connection to be fully established using ViaMaterialized
2. Start active reading with readSub.Request(1) to trigger recv() on Linux
3. Then abort - ensuring RST detection works reliably across platforms

This makes the test behave like real applications that immediately start
using their TCP connections, which is why real apps don't have this issue.

Fixes the race condition that caused 11 failed attempts in PR #7813.

(cherry picked from commit 6aee8bd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant