From 546ea578cfbf7b4754669a089109378aa5814331 Mon Sep 17 00:00:00 2001 From: Subodh Iyengar Date: Thu, 29 Sep 2016 06:42:11 -0700 Subject: [PATCH] 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 --- folly/io/async/AsyncSocket.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; -- 2.34.1