diff options
author | mruddy <6440430+mruddy@users.noreply.github.com> | 2018-11-08 06:38:21 -0500 |
---|---|---|
committer | mruddy <6440430+mruddy@users.noreply.github.com> | 2018-11-15 08:16:25 -0500 |
commit | c276df775914e4e42993c76e172ef159e3b830d4 (patch) | |
tree | 8bba4fee9755974b946a1d95aac811aa1c8b61e0 | |
parent | e74649e95122c9c61aadf607461cf701c3953f88 (diff) |
zmq: enable tcp keepalive
-rw-r--r-- | doc/zmq.md | 14 | ||||
-rw-r--r-- | src/zmq/zmqpublishnotifier.cpp | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/doc/zmq.md b/doc/zmq.md index 7ffc5623b6..35bb0fc377 100644 --- a/doc/zmq.md +++ b/doc/zmq.md @@ -98,6 +98,20 @@ ZMQ_SUBSCRIBE option set to one or either of these prefixes (for instance, just `hash`); without doing so will result in no messages arriving. Please see `contrib/zmq/zmq_sub.py` for a working example. +The ZMQ_PUB socket's ZMQ_TCP_KEEPALIVE option is enabled. This means that +the underlying SO_KEEPALIVE option is enabled when using a TCP transport. +The effective TCP keepalive values are managed through the underlying +operating system configuration and must be configured prior to connection establishment. + +For example, when running on GNU/Linux, one might use the following +to lower the keepalive setting to 10 minutes: + +sudo sysctl -w net.ipv4.tcp_keepalive_time=600 + +Setting the keepalive values appropriately for your operating environment may +improve connectivity in situations where long-lived connections are silently +dropped by network middle boxes. + ## Remarks From the perspective of bitcoind, the ZeroMQ socket is write-only; PUB diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 15d4ac1b89..e2177efe56 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -86,6 +86,14 @@ bool CZMQAbstractPublishNotifier::Initialize(void *pcontext) return false; } + const int so_keepalive_option {1}; + rc = zmq_setsockopt(psocket, ZMQ_TCP_KEEPALIVE, &so_keepalive_option, sizeof(so_keepalive_option)); + if (rc != 0) { + zmqError("Failed to set SO_KEEPALIVE"); + zmq_close(psocket); + return false; + } + rc = zmq_bind(psocket, address.c_str()); if (rc != 0) { |