mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2026-01-06 11:00:10 -06:00
Correctly return errors when failing to connect
Triggered by investigating
xmon: could not read message type: unexpected EOF, will reconnect
xmon: connected to xmon REDACTED
Undertaker: hard abort - running abort handlers
Uncaught exception thrown: SyscallException(Xmon.cpp@186, 9/EBADF=Bad file descriptor in void Xmon::run()): setsockopt
which caused crashes in shards/CDC.
This commit is contained in:
@@ -16,6 +16,10 @@ static std::string explicitGenerateErrString(const std::string& what, int err, c
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
static std::string generateErrString(const std::string& what, int err) {
|
||||
return explicitGenerateErrString(what, err, (std::string(translateErrno(err)) + "=" + safe_strerror(err)).c_str());
|
||||
}
|
||||
|
||||
int connectToHost(
|
||||
const std::string& host,
|
||||
uint16_t port,
|
||||
@@ -52,11 +56,15 @@ int connectToHost(
|
||||
throw SYSCALL_EXCEPTION("socket");
|
||||
}
|
||||
|
||||
if (synRetries >= 0) {
|
||||
setsockopt(infoSock, IPPROTO_TCP, TCP_SYNCNT, &synRetries, sizeof(synRetries));
|
||||
if (synRetries > 0) {
|
||||
if (setsockopt(infoSock, IPPROTO_TCP, TCP_SYNCNT, &synRetries, sizeof(synRetries)) < 0) {
|
||||
errString = generateErrString("setsockopt", errno);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (connect(infoSock, info->ai_addr, info->ai_addrlen) < 0) {
|
||||
errString = generateErrString("connect", errno);
|
||||
close(infoSock);
|
||||
} else {
|
||||
fd = infoSock;
|
||||
@@ -64,5 +72,9 @@ int connectToHost(
|
||||
}
|
||||
}
|
||||
|
||||
// we've managed to connect, clear earlier errors
|
||||
if (fd != -1) {
|
||||
errString = "";
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ static ShuckleSock shuckleSock(const std::string& host, uint16_t port, Duration
|
||||
// We retry upstream anyway, and we want prompt termination of `connect`.
|
||||
// If we don't do this, mistakenly trying to connect to an iceland shuckle (currently
|
||||
// the default) will hang for a long time.
|
||||
sock.fd = connectToHost(host, port, 0, errString);
|
||||
sock.fd = connectToHost(host, port, 1, errString);
|
||||
|
||||
if (sock.fd >= 0) {
|
||||
struct timeval tv;
|
||||
|
||||
Reference in New Issue
Block a user