Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    Repair Half-Closed Socket Bugs

    by Mariusz Wrzeszczynski

    1

    Repair TCP half-close bugs that truncate responses, destroy both directions on EOF, omit FIN propagation, or leave writers hanging.

    Secure checkout via Stripe

    0 installsSecurity scanned

    See it in action

    You say

    Our Go TCP tunnel runs io.Copy in both directions. When the client finishes uploading it sends FIN, the client-to-upstream copy returns EOF, and our goroutine closes both connections immediately. The upstream may still send a final response, which is intermittently truncated. Repair locally using disposable loopback listeners and deterministic barriers. Preserve current deadlines and protocol framing; do not connect to production or add retries.

    Your agent does

    Directional close bug found. The upstream read loop treats orderly EOF as authority to destroy both sockets, so downstream response bytes can be truncated. The repair separates read completion from final teardown, propagates supported CloseWrite deliberately, drains approved buffers, and validates both FIN orderings on disposable loopback sockets.

    What you get

    Prevent response truncation when a client finishes sending its request body.Implement graceful CloseWrite propagation in TCP-to-TLS protocol bridges.Decouple read-loop completion from connection destruction in stream adapters.Add deterministic tests for edge-case socket shutdown sequences.

    About this skill

    The problem

    TCP proxies, tunnels, and stream adapters often treat a read EOF as a signal to kill the entire connection. This leads to truncated responses, hung writers, and race conditions when one peer finishes sending but still needs to receive data.

    What it does

    • Identifies incorrect socket shutdown logic in proxies, relays, and protocol bridges.
    • Implements directional CloseWrite/FIN propagation to ensure data drains before cleanup.
    • Refactors read loops to decouple stream completion from socket destruction.
    • Builds deterministic loopback tests to verify specific FIN/EOF ordering and buffer boundaries.
    • Adds observability for peer EOF, local FIN, and truncation events.

    Frameworks & tools

    Works with low-level networking code in Node.js (allowHalfOpen), Go (TCPConn), C/C++, and Rust. Compatible with TCP, TLS wrappers, and custom protocol tunnels.

    Why this beats prompting it yourself

    General LLMs often assume EOF means "the connection is over," which is fatal for many protocols. This skill enforces a strict directional socket register and synchronization contract to prevent data loss in half-closed states.

    Use cases

    • Fixing tunnels where the client connection drops before the server finishes responding.
    • Repairing proxy relays that truncate buffered data after a peer sends a FIN.
    • Resolving deadlocks in request-response flows over raw TCP sockets.
    • Migrating raw TCP close semantics to TLS close_notify without breaking stream logic.

    Known limitations

    Cannot verify middlebox or ISP-level packet interference. Requires repository access to local socket fixtures for validation.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Frequently Asked Questions

    Popular in API Development