Skip to content

fix: Remove KeepAlive socket option#1671

Merged
HofmeisterAn merged 1 commit intotestcontainers:developfrom
Angelinsky7:fix/client-fail-socket-keep-alive
Mar 24, 2026
Merged

fix: Remove KeepAlive socket option#1671
HofmeisterAn merged 1 commit intotestcontainers:developfrom
Angelinsky7:fix/client-fail-socket-keep-alive

Conversation

@Angelinsky7
Copy link
Contributor

@Angelinsky7 Angelinsky7 commented Mar 24, 2026

What does this PR do?

On some platform the TCPClient fail to connect because of KeepAlive settings.

Why is it important?

If the client fail to connect, TestContainer does not work at all.

Related issues

Relates dotnet/runtime#24917
Closes #1670

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of resource connection stability on certain platforms.

@netlify
Copy link

netlify bot commented Mar 24, 2026

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 77128ad
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/69c24537bc8b97000857e93d
😎 Deploy Preview https://deploy-preview-1671--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2026

Walkthrough

Removes the TCP keep-alive socket option assignment from ResourceReaper.MaintainRyukConnection and replaces it with commented-out code and a note referencing a PlatformNotSupportedException scenario. This reverts a change that caused Ryuk connection failures in certain environments following the 4.11.0 upgrade.

Changes

Cohort / File(s) Summary
Ryuk Keep-Alive Socket Configuration
src/Testcontainers/Containers/ResourceReaper.cs
Removed tcpClient.Client.SetSocketOption() call for TCP keep-alive; replaced with commented-out code and explanatory note referencing platform exception handling.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰 A socket once kept so alive,
Caused Ryuk's connection to dive,
We've commented it out,
No more connection drought,
Now the reaper and client both thrive! 🔌✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description includes what the PR does and why it's important, but lacks recommended 'How to test' section and doesn't provide explicit step-by-step testing guidance.
Linked Issues check ✅ Passed The PR directly addresses issue #1670 by removing the KeepAlive socket option that was causing client connection failures on some platforms, meeting the core requirement.
Out of Scope Changes check ✅ Passed All changes are scoped to the ResourceReaper.cs file and directly address the KeepAlive socket issue causing the connection regression; no out-of-scope modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title accurately summarizes the main change: removing the KeepAlive socket option from the TCP client connection to fix a platform-specific connection failure issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/Testcontainers/Containers/ResourceReaper.cs (1)

307-308: Clean up the KeepAlive note (typo + commented-out code).

Line 307 has a typo (“plateform”), and Line 308 leaves disabled code in place. Prefer a plain rationale comment (with issue reference) instead of commented-out executable code.

Suggested cleanup
-          // On some plateform the connection fail with PlatformNotSupportedException: Sockets on this platform are invalid for use after a failed connection attempt.
-          // tcpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
+          // KeepAlive is intentionally not set due to platform-specific failures after failed connect attempts.
+          // See: https://github.com/dotnet/runtime/issues/24917.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Testcontainers/Containers/ResourceReaper.cs` around lines 307 - 308, In
ResourceReaper where the KeepAlive note appears, replace the typo-filled comment
and the commented-out tcpClient.Client.SetSocketOption(...) line with a concise
rationale: correct "plateform" to "platform", remove the disabled code, and add
a short comment stating that KeepAlive calls were intentionally omitted because
they can throw PlatformNotSupportedException on some platforms (include an
internal issue/PR reference if needed); locate the comment near the TcpClient
usage (the code that previously referenced tcpClient.Client.SetSocketOption) and
update it accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/Testcontainers/Containers/ResourceReaper.cs`:
- Around line 307-308: In ResourceReaper where the KeepAlive note appears,
replace the typo-filled comment and the commented-out
tcpClient.Client.SetSocketOption(...) line with a concise rationale: correct
"plateform" to "platform", remove the disabled code, and add a short comment
stating that KeepAlive calls were intentionally omitted because they can throw
PlatformNotSupportedException on some platforms (include an internal issue/PR
reference if needed); locate the comment near the TcpClient usage (the code that
previously referenced tcpClient.Client.SetSocketOption) and update it
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 71183c3f-273c-496a-a53c-63debf4fade4

📥 Commits

Reviewing files that changed from the base of the PR and between 598f961 and 77128ad.

📒 Files selected for processing (1)
  • src/Testcontainers/Containers/ResourceReaper.cs

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Mar 24, 2026
@HofmeisterAn HofmeisterAn changed the title fix: remove KeepAlive setting from socket connection fix: Remove KeepAlive socket option Mar 24, 2026
Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@HofmeisterAn HofmeisterAn merged commit 524bade into testcontainers:develop Mar 24, 2026
100 of 152 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Client fail to connect to Ryuk with keepAlive socket

2 participants