The occasional ECONNRESET

(movq.de)

65 points | by zdw 4 hours ago ago

15 comments

  • smarks 2 hours ago

    Part 2 shows this comment from the Linux TCP code:

        /* As outlined in RFC 2525, section 2.17, we send a RST here because
         * data was lost. To witness the awful effects of the old behavior of
         * always doing a FIN, run an older 2.1.x kernel or 2.0.x, start a bulk
         * GET in an FTP client, suspend the process, wait for the client to
         * advertise a zero window, then kill -9 the FTP client, wheee...
         * Note: timeout is always zero in such a case.
         */
    
    Ok, so the RST is explained and well justified by the literature. But what are the “awful effects” of sending FIN instead? Can someone explain?
    • buckle8017 2 hours ago

      Client sees a clean disconnect and I guess assumes thats the entire file?

      • amluto an hour ago

        The client has been SIGKILLed, so it’s not assuming anything. I wonder whether the comment is a typo and they meant to kill -9 the server instead.

        • jmalicki 18 minutes ago

          Hypothetically if this was HTTP without a Content-length (like it used to be in the olden days), you could have a proxy server assume this is the entire file.

        • MrBuddyCasino an hour ago

          Perhaps a permanently hung connection because timeout is zero (=disabled?)?

          • muststopmyths 18 minutes ago

            Seems plausible since FIN only means “I’m done sending” also called a “half close”.

            FTP has different data and command connections so the server may not have an outstanding read to detect the data connection break.

            But.. it should still clean up both when the command connection dies

  • toast0 3 hours ago

    Might want to read the section on Lingering Close from here:

    https://httpd.apache.org/docs/2.4/misc/perf-tuning.html

    • zokier 2 hours ago

      That seems very outdated? Doesn't `shutdown` resolve the problem here?

      • toast0 24 minutes ago

        Shutdown only helps if it's used; but TFA didn't mention it. So they're going to have to relearn the lessons of the 90s?

        Also, I think state of the art hasn't really changed? If you don't want a reset, you need to read everything from the socket before you close. If you don't really care about a reset as long as it doesn't interrupt the reader, you can shutdown in your direction, and drop the socket off to something that will wait "long enough" before it closes. In an eventloop architecture, you can just put in as a deferred task; in process per connection, you should probably send the socket to a dedicated lingering closer process that doesn't interrupt your flow.

  • gunsch an hour ago

    A few months ago I was debugging a similar issue in a Go-based service layer, where frequent HTTP requests to the same domain kept making fresh TCP connections when I was expecting TCP conn reuse.

    In this situation we were discarding the HTTP response without reading it before closing, which kept Go from reusing the connection. I didn't dig quite as deep as this post's author, but I imagine the same RST behavior was happening under the hood.

  • Joker_vD 3 hours ago

    > Send off the data and close the socket. If there's data still pending to be read, this will cause a RST, I think.

    Um, yes? That's how TCP has been universally implemented for more than 30 years. See [0], 2.17 for discussion.

    [0] https://www.rfc-editor.org/rfc/rfc2525#page-50

    • eggnet 2 hours ago

      That’s for rx, not tx. When you close a socket with data in the send buffer, that does not trigger a RST. If you just close the socket normally.

      • pdonis 2 hours ago

        > When you close a socket with data in the send buffer

        That's not what's happening here. The server is closing the socket when there's data from the client that it hasn't read.

        • Joker_vD 2 hours ago

          Yep, and that makes implementing addition of "Connection: close" in an HTTP reply at the HTTP/1.1-server's side somewhat tricky: you ideally need to read all of the pipelined requests from the client before closing the connection, which is usually something you'd rather not do. But if you just close it, you risk your client getting a partial reply, so you better add "Content-Length"/"Transfer-Encoding: chunked" in your reply as well... but one common reason to do connection-close reply is when you don't know the content-length beforehand, so — I hope you implemented chunking correctly :)

          • toast0 12 minutes ago

            More explicit connection closing indications are one of the nice things of http/2. Of course, it's bundled with the silly multiplexing :(