Skip to content

Commit

Permalink
wsd: net: handle unexpected closed-socket gracefully
Browse files Browse the repository at this point in the history
Previously, we threw an exception in this case,
which had a couple of unfortunately side-effects.

First, the onDisconnect() handler wasn't called.
This prevented proper reconnection logic in some
cases.

Second, it created different behavior depending
on _how_ we detected the disconnection. That is,
depending on the value of the various return values
and error codes, we either threw or returned with
errno.

This treats all disconnection/unexpected socket
errors as EPIPE and returns 0.

Change-Id: Ia27a055a3cbcf639c62b82506f7cb683e99146f2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
  • Loading branch information
Ashod authored and mmeeks committed Jan 10, 2025
1 parent 23ccfaf commit 4190f66
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions net/SslSocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@ class SslStreamSocket final : public StreamSocket
{
// Socket closed. Not an error.
oss << " (" << context << "): closed. " << bioErrStr;
LOG_INF(oss.str());
return 0;
}
else if (rc == -1)
{
Expand All @@ -479,9 +477,7 @@ class SslStreamSocket final : public StreamSocket
}

oss << bioErrStr;
const std::string msg = oss.str();
LOG_TRC("Throwing SSL Error ("
<< context << "): " << msg); // Locate the source of the exception.
LOG_DBG("SSL Error (" << context << "): " << oss.str());

handshakeFail();

Expand All @@ -490,13 +486,12 @@ class SslStreamSocket final : public StreamSocket
if (!sslVerifyResult.empty())
LOG_ERR("SSL verification warning (" << context << "): " << sslVerifyResult);

errno = last_errno; // Restore errno before throwing.
throw std::runtime_error(msg);
last_errno = last_errno ? last_errno : EPIPE; // Set errno if unset.
return 0; // EOF.
}
break;
}

errno = last_errno; // Restore errno.
return rc;
}

Expand Down

0 comments on commit 4190f66

Please sign in to comment.