diff --git a/envoy/common/platform.h b/envoy/common/platform.h index a877e91083d1..42075f881f80 100644 --- a/envoy/common/platform.h +++ b/envoy/common/platform.h @@ -329,3 +329,9 @@ struct mmsghdr { // On non-Linux platforms use 128 which is libevent listener default #define ENVOY_TCP_BACKLOG_SIZE 128 #endif + +#if defined(__linux__) +#define ENVOY_PLATFORM_ENABLE_SEND_RST 1 +#else +#define ENVOY_PLATFORM_ENABLE_SEND_RST 0 +#endif diff --git a/source/common/network/connection_impl.cc b/source/common/network/connection_impl.cc index b6858939f517..0f23f22da1ca 100644 --- a/source/common/network/connection_impl.cc +++ b/source/common/network/connection_impl.cc @@ -292,12 +292,14 @@ void ConnectionImpl::closeSocket(ConnectionEvent close_type) { if (enable_rst_detect_send_ && (detected_close_type_ == DetectedCloseType::RemoteReset || detected_close_type_ == DetectedCloseType::LocalReset)) { +#if ENVOY_PLATFORM_ENABLE_SEND_RST const bool ok = Network::Socket::applyOptions( Network::SocketOptionFactory::buildZeroSoLingerOptions(), *socket_, envoy::config::core::v3::SocketOption::STATE_LISTENING); if (!ok) { ENVOY_LOG_EVERY_POW_2(error, "rst setting so_linger=0 failed on connection {}", id()); } +#endif } // It is safe to call close() since there is an IO handle check. diff --git a/test/common/network/connection_impl_test.cc b/test/common/network/connection_impl_test.cc index 7f768eea8c21..b6eba1589150 100644 --- a/test/common/network/connection_impl_test.cc +++ b/test/common/network/connection_impl_test.cc @@ -640,6 +640,7 @@ TEST_P(ConnectionImplTest, SocketOptionsFailureTest) { dispatcher_->run(Event::Dispatcher::RunType::Block); } +#if ENVOY_PLATFORM_ENABLE_SEND_RST // Test that connection is AbortReset closed during callback. TEST_P(ConnectionImplTest, ClientAbortResetDuringCallback) { Network::ClientConnectionPtr upstream_connection_; @@ -786,6 +787,7 @@ TEST_P(ConnectionImplTest, ServerResetCloseRuntimeDisabled) { server_connection_->close(ConnectionCloseType::AbortReset); dispatcher_->run(Event::Dispatcher::RunType::Block); } +#endif struct MockConnectionStats { Connection::ConnectionStats toBufferStats() { @@ -1111,6 +1113,7 @@ TEST_P(ConnectionImplTest, CloseOnReadDisableWithoutCloseDetection) { dispatcher_->run(Event::Dispatcher::RunType::Block); } +#if ENVOY_PLATFORM_ENABLE_SEND_RST // Test normal RST close without readDisable. TEST_P(ConnectionImplTest, RstCloseOnNotReadDisabledConnection) { setUpBasicConnection(); @@ -1188,6 +1191,7 @@ TEST_P(ConnectionImplTest, RstCloseOnReadEarlyCloseDisabledThenWrite) { client_connection_->write(buffer, false); dispatcher_->run(Event::Dispatcher::RunType::Block); } +#endif // Test that connection half-close is sent and received properly. TEST_P(ConnectionImplTest, HalfClose) { @@ -1229,6 +1233,7 @@ TEST_P(ConnectionImplTest, HalfClose) { dispatcher_->run(Event::Dispatcher::RunType::Block); } +#if ENVOY_PLATFORM_ENABLE_SEND_RST // Test that connection is immediately closed when RST is detected even // half-close is enabled TEST_P(ConnectionImplTest, HalfCloseResetClose) { @@ -1346,7 +1351,6 @@ TEST_P(ConnectionImplTest, HalfCloseThenResetClose) { dispatcher_->run(Event::Dispatcher::RunType::Block); } -#if !defined(WIN32) // Test that no remote close event will be propagated back to peer, when a connection is // half-closed and then the connection is RST closed. Writing data to the half closed and then // reset connection will lead to broken pipe error rather than reset error. diff --git a/test/integration/tcp_async_client_integration_test.cc b/test/integration/tcp_async_client_integration_test.cc index 8550b9b601f0..cd31af091dd9 100644 --- a/test/integration/tcp_async_client_integration_test.cc +++ b/test/integration/tcp_async_client_integration_test.cc @@ -111,6 +111,7 @@ TEST_P(TcpAsyncClientIntegrationTest, MultipleResponseFrames) { tcp_client->close(); } +#if ENVOY_PLATFORM_ENABLE_SEND_RST // Test if RST close can be detected from downstream and upstream is closed by RST. TEST_P(TcpAsyncClientIntegrationTest, TestClientCloseRST) { enableHalfClose(true); @@ -175,7 +176,6 @@ TEST_P(TcpAsyncClientIntegrationTest, TestUpstreamCloseRST) { tcp_client->waitForDisconnect(); } -#if !defined(WIN32) // Test the behaviour when the connection is half closed and then the connection is reset by // the client. The behavior is different for windows, since RST support is literally supported for // unix like system, disabled the test for windows.