Skip to content

Backport: harden TcpSpec abort/connection-fails + EventFilterTestBase races (#7815, #7870, #7797) - #8302

Merged
Aaronontheweb merged 4 commits into
akkadotnet:v1.5from
Aaronontheweb:backport/v1.5-tcpspec-abort-dns-eventfilter-flaky
Jul 2, 2026
Merged

Aaronontheweb merged 4 commits into
akkadotnet:v1.5from
Aaronontheweb:backport/v1.5-tcpspec-abort-dns-eventfilter-flaky

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Member

Summary

Test-only backport to v1.5 of three flaky-test fixes from dev. Three individual commits, one per source PR. No production code is touched.

Fix (source PR) Test stabilized What it does
#7815 (6aee8bd70, cherry-pick -x) Outgoing_TCP_stream_must_shut_down_both_streams_when_connection_is_aborted_remotely (TcpSpec) Waits for the client connection to be fully materialized (ViaMaterialized(..., Keep.Right) + await connectionTask) and starts active reading (readSub.Request(1)) before the remote Abort(), so Linux epoll actually issues the recv() that detects the TCP RST. Switches the assertion to ExpectErrorAsync().
#7870 (8c094522c, cherry-pick -x) Outgoing_TCP_stream_must_fail_the_materialized_task_when_the_connection_fails (TcpSpec) Replaces new DnsEndPoint("example.com", 666) with new IPEndPoint(IPAddress.Parse("192.0.2.1"), 666) (TEST-NET-1, non-routable) so the connection attempt starts immediately instead of waiting on DNS resolution.
#7797 (partial, hand-authored) Every spec deriving from EventFilterTestBase (Akka.TestKit.Tests) Retries logger initialization via AwaitAssertAsync until the ForwardAllEventsTestEventListener acknowledges with "OK", instead of a single blocking SendRawLogEventMessage/ExpectMsg that can run before the logger has finished subscribing.

Notes / honest caveats

This PR is standalone and separate from the other v1.5 flaky-test backports (#8296 / #8298 / #8300 / #8301).

Local validation (Linux, net10.0)

  • dotnet build Akka.Streams.Tests -c Release -warnaserror --framework net10.0 -> 0 warnings, 0 errors
  • dotnet build Akka.TestKit.Tests -c Release -warnaserror --framework net10.0 -> 0 warnings, 0 errors
  • Abort test x5 (~shut_down_both_streams_when_connection_is_aborted) -> 5/5 pass
  • Connection-fails test (~fail_the_materialized_task_when_the_connection_fails) -> pass
  • EventFilterTestBase-derived specs (~EventFilter, 220 tests) x5 -> 5/5 pass (220/220 each)

Aaronontheweb and others added 4 commits July 2, 2026 20:41
…net#7815)

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.

(cherry picked from commit 6aee8bd)
Replace DNS hostname with direct IP address to eliminate non-deterministic
DNS resolution timing. The test was experiencing flaky failures because
DNS resolution for example.com could take 2+ seconds, leaving insufficient
time for the connection timeout to fire before the test timeout.

Changed from DnsEndPoint("example.com", 666) to IPEndPoint(192.0.2.1, 666)
using TEST-NET-1 reserved address. This ensures the connection attempt
starts immediately without DNS delays, allowing the connection timeout to
fire reliably within the 1-second window.

(cherry picked from commit 8c09452)
…rtial)

Retry logger initialization with AwaitAssertAsync until the
ForwardAllEventsTestEventListener acknowledges with "OK", instead of a
single blocking SendRawLogEventMessage/ExpectMsg that can run before the
logger has finished subscribing.

Hand-authored partial backport of akkadotnet#7797: only the EventFilterTestBase
portion is ported here, keeping v1.5's xUnit-3 `async ValueTask
InitializeAsync` signature. The original akkadotnet#7797 also rewrote the TcpSpec
`...terminates_unexpectedly` test (intentionally excluded — that fix was
backported separately via akkadotnet#8301) and applied cosmetic collection-literal
changes to two other TcpSpec methods (no behavior change, skipped).

Also satisfies the repo guidance to prefer async TestKit methods
(sync ExpectMsg -> await ExpectMsgAsync).
@Aaronontheweb
Aaronontheweb enabled auto-merge (rebase) July 2, 2026 20:53
@Aaronontheweb
Aaronontheweb merged commit 0d0c953 into akkadotnet:v1.5 Jul 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant