summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Orttung <nathan@orttung.com>2018-06-22 16:25:17 -0400
committerNathan Orttung <nathan@orttung.com>2018-06-28 17:20:09 -0400
commit95b28a323db94dcde627702289dea8a76232ece4 (patch)
tree773a7a8b2400f701ddc2138ff02dc56a88da841c
parentb5dcbd7a26a8452de61a79dc40e9c569e9344d24 (diff)
downloadmongo-95b28a323db94dcde627702289dea8a76232ece4.tar.gz
SERVER-29359 SO_KEEPALIVE for nia sockets
Previously had not set keepalives for egress sockets on executors, this fixes that. (cherry picked from commit bcacc4929dcddc4e6c380aa41b2db730245de244)
-rw-r--r--src/mongo/executor/SConscript1
-rw-r--r--src/mongo/executor/async_secure_stream.cpp5
-rw-r--r--src/mongo/executor/async_stream.cpp5
-rw-r--r--src/mongo/executor/async_stream_common.cpp5
-rw-r--r--src/mongo/executor/async_stream_common.h13
5 files changed, 29 insertions, 0 deletions
diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript
index ed040af2910..0359c40a020 100644
--- a/src/mongo/executor/SConscript
+++ b/src/mongo/executor/SConscript
@@ -168,6 +168,7 @@ env.Library(
LIBDEPS=[
'$BUILD_DIR/mongo/base/system_error',
'$BUILD_DIR/mongo/client/authentication',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/third_party/shim_asio',
'task_executor_interface',
]
diff --git a/src/mongo/executor/async_secure_stream.cpp b/src/mongo/executor/async_secure_stream.cpp
index 0c7969024f7..a7c051bc34b 100644
--- a/src/mongo/executor/async_secure_stream.cpp
+++ b/src/mongo/executor/async_secure_stream.cpp
@@ -74,6 +74,11 @@ void AsyncSecureStream::connect(asio::ip::tcp::resolver::iterator endpoints,
return _userHandler(ec);
}
+ ec = setStreamKeepAlive(&_stream.next_layer());
+ if (ec) {
+ return _userHandler(ec);
+ }
+
_connected = true;
return _handleConnect(std::move(iter));
}));
diff --git a/src/mongo/executor/async_stream.cpp b/src/mongo/executor/async_stream.cpp
index 075a9094dd4..aeafd8a0b8b 100644
--- a/src/mongo/executor/async_stream.cpp
+++ b/src/mongo/executor/async_stream.cpp
@@ -70,6 +70,11 @@ void AsyncStream::connect(tcp::resolver::iterator iter, ConnectHandler&& connect
return connectHandler(ec);
}
+ ec = setStreamKeepAlive(&_stream);
+ if (ec) {
+ return connectHandler(ec);
+ }
+
_connected = true;
return connectHandler(ec);
}));
diff --git a/src/mongo/executor/async_stream_common.cpp b/src/mongo/executor/async_stream_common.cpp
index 92708862c94..97cfb3115b0 100644
--- a/src/mongo/executor/async_stream_common.cpp
+++ b/src/mongo/executor/async_stream_common.cpp
@@ -57,6 +57,11 @@ void logFailureInSetStreamNoDelay(std::error_code ec) {
severe() << "Failed to set no-delay mode on stream: " << ec.message();
}
+void logFailureInSetStreamKeepAlive(std::error_code ec) {
+ invariant(ec);
+ severe() << "Failed to set keep-alive mode on stream: " << ec.message();
+}
+
void logUnexpectedErrorInCheckOpen(std::error_code ec) {
invariant(ec);
log() << "unexpected error when checking if a stream was open: " << ec.message()
diff --git a/src/mongo/executor/async_stream_common.h b/src/mongo/executor/async_stream_common.h
index 67c12bbff3b..5ca7dcad5fe 100644
--- a/src/mongo/executor/async_stream_common.h
+++ b/src/mongo/executor/async_stream_common.h
@@ -31,6 +31,7 @@
#include <utility>
#include "mongo/util/assert_util.h"
+#include "mongo/util/net/sock.h"
namespace mongo {
namespace executor {
@@ -93,6 +94,7 @@ void cancelStream(ASIOStream* stream) {
void logFailureInSetStreamNonBlocking(std::error_code ec);
void logFailureInSetStreamNoDelay(std::error_code ec);
+void logFailureInSetStreamKeepAlive(std::error_code ec);
template <typename ASIOStream>
std::error_code setStreamNonBlocking(ASIOStream* stream) {
@@ -114,6 +116,17 @@ std::error_code setStreamNoDelay(ASIOStream* stream) {
return ec;
}
+template <typename ASIOStream>
+std::error_code setStreamKeepAlive(ASIOStream* stream) {
+ std::error_code ec;
+ stream->set_option(asio::socket_base::keep_alive(true), ec);
+ if (ec) {
+ logFailureInSetStreamKeepAlive(ec);
+ }
+ setSocketKeepAliveParams(stream->native_handle());
+ return ec;
+}
+
void logUnexpectedErrorInCheckOpen(std::error_code ec);
template <typename ASIOStream>