Commit 546ea578 authored by Subodh Iyengar's avatar Subodh Iyengar Committed by Facebook Github Bot

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
parent edbb8ae9
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment