Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply env(ICECC_SLOW_NETWORK) also to setsockopt() #623

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2017,11 +2017,11 @@ void Daemon::answer_client_requests()
pfd.fd = scheduler->fd;
pfd.events = POLLIN;
pollfds.push_back(pfd);
} else if (discover && discover->listen_fd() >= 0) {
} else if (discover && (discover->listen_fd() >= 0 || discover->connect_fd() >= 0)) {
/* We don't explicitely check for discover->get_fd() being in
the selected set below. If it's set, we simply will return
and our call will make sure we try to get the scheduler. */
pfd.fd = discover->listen_fd();
pfd.fd = discover->listen_fd() >= 0 ? discover->listen_fd() : discover->connect_fd();
pfd.events = POLLIN;
pollfds.push_back(pfd);
}
Expand Down
35 changes: 26 additions & 9 deletions services/comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,27 @@ void MsgChannel::writefull(const void *_buf, size_t count)
msgtogo += count;
}

bool MsgChannel::slow_network()
{
static bool retval = false;
static bool cached = false;
if (!cached) {
if (const char *icecc_slow_network = getenv("ICECC_SLOW_NETWORK"))
if (icecc_slow_network[0] == '1')
retval = true;
cached = true;
}
return retval;
}

static size_t get_max_write_size()
{
if( const char* icecc_slow_network = getenv( "ICECC_SLOW_NETWORK" ))
if( icecc_slow_network[ 0 ] == '1' )
return MAX_SLOW_WRITE_SIZE;
return MAX_MSG_SIZE;
return MsgChannel::slow_network() ? MAX_SLOW_WRITE_SIZE : MAX_MSG_SIZE;
}

static size_t get_write_timeout_secs()
{
return MsgChannel::slow_network() ? 60 * 60 : 30;
}

bool MsgChannel::flush_writebuf(bool blocking)
Expand Down Expand Up @@ -381,7 +396,7 @@ bool MsgChannel::flush_writebuf(bool blocking)
pollfd pfd;
pfd.fd = fd;
pfd.events = POLLOUT;
ready = poll(&pfd, 1, 30 * 1000);
ready = poll(&pfd, 1, get_write_timeout_secs() * 1000);

if (ready < 0 && errno == EINTR) {
continue;
Expand All @@ -395,7 +410,7 @@ bool MsgChannel::flush_writebuf(bool blocking)
continue;
}
if (ready == 0) {
log_error() << "timed out while trying to send data" << endl;
log_error() << "timed out (" << get_write_timeout_secs() << " seconds) while trying to send data" << endl;
}

/* Timeout or real error --> error. */
Expand Down Expand Up @@ -946,7 +961,7 @@ MsgChannel::MsgChannel(int _fd, struct sockaddr *_a, socklen_t _l, bool text)

int on = 1;

if (!setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on))) {
if (!setsockopt(_fd, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof(on)) && !slow_network()) {
#if defined( TCP_KEEPIDLE ) || defined( TCPCTL_KEEPIDLE )
#if defined( TCP_KEEPIDLE )
int keepidle = TCP_KEEPIDLE;
Expand Down Expand Up @@ -977,8 +992,10 @@ MsgChannel::MsgChannel(int _fd, struct sockaddr *_a, socklen_t _l, bool text)
}

#ifdef TCP_USER_TIMEOUT
int timeout = 3 * 3 * 1000; // matches the timeout part of keepalive above, in milliseconds
setsockopt(_fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *) &timeout, sizeof(timeout));
if (!slow_network()) {
int timeout = 3 * 3 * 1000; // matches the timeout part of keepalive above, in milliseconds
setsockopt(_fd, IPPROTO_TCP, TCP_USER_TIMEOUT, (char *) &timeout, sizeof(timeout));
}
#endif

if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
Expand Down
6 changes: 4 additions & 2 deletions services/comm.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
// if you increase the MIN_PROTOCOL_VERSION, comment out macros below and clean up the code
#define MIN_PROTOCOL_VERSION 21

#define MAX_SCHEDULER_PONG 3
#define MAX_SCHEDULER_PONG (!MsgChannel::slow_network() ? 3 : 300)
// MAX_SCHEDULER_PING must be multiple of MAX_SCHEDULER_PONG
#define MAX_SCHEDULER_PING 12 * MAX_SCHEDULER_PONG
// maximum amount of time in seconds a daemon can be busy installing
#define MAX_BUSY_INSTALLING 120
#define MAX_BUSY_INSTALLING (!MsgChannel::slow_network() ? 120 : 10 * 60 * 60)

// comparison for protocol version checks
#define IS_PROTOCOL_VERSION(x, c) ((c)->protocol >= (x))
Expand Down Expand Up @@ -284,6 +284,8 @@ class MsgChannel
MsgChannel &operator<<(const std::string &);
MsgChannel &operator<<(const std::list<std::string> &);

static bool slow_network();

// our filedesc
int fd;

Expand Down