From: Subodh Iyengar Date: Thu, 29 Sep 2016 13:42:11 +0000 (-0700) Subject: Fix apple bug around TFO writes X-Git-Tag: v2016.10.03.00~6 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=546ea578cfbf7b4754669a089109378aa5814331;p=folly.git Fix apple bug around TFO writes Summary: When using connectx to do TFO, apple has a bug where the second write after a TFO write will cause the socket to throw an ENOTCONN error instead of an EAGAIN. Linux handles this case fine and returns an EAGAIN, however apple returns ENOTCONN. We solve this by treating ENOTCONN as an EAGAIN temporarily. Reviewed By: yfeldblum Differential Revision: D3942681 fbshipit-source-id: ab4f0b5fd6cdcfe9c584ea00849705a2d739d65f --- diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index beafbe5f..bb41685d 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -1870,7 +1870,15 @@ AsyncSocket::WriteResult AsyncSocket::performWrite( auto writeResult = sendSocketMessage(fd_, &msg, msg_flags); auto totalWritten = writeResult.writeReturn; if (totalWritten < 0) { - if (!writeResult.exception && errno == EAGAIN) { + bool tryAgain = (errno == EAGAIN); +#ifdef __APPLE__ + // Apple has a bug where doing a second write on a socket which we + // have opened with TFO causes an ENOTCONN to be thrown. However the + // socket is really connected, so treat ENOTCONN as a EAGAIN until + // this bug is fixed. + tryAgain |= (errno == ENOTCONN); +#endif + if (!writeResult.exception && tryAgain) { // TCP buffer is full; we can't write any more data right now. *countWritten = 0; *partialWritten = 0;