Skip to content

Commit 2df9b59

Browse files
authored
Fix bus error from boost socket.shutdown in tcp_socket_error() and link statically to OpenSSL (#145)
* Fix bus error from boost socket.shutdown in tcp_socket_error() Under MacOS (Darwin 23.1, arm64), building with Boost 1.81.0, localproxytest test-cases 'Test source mode" and 'Test source mode with client token' fail due to a bus error when calling connection->socket_.shutdown in tcp_adapter_proxy::tcp_socket_error. The exact same issue is triggered in localproxy, when a connection that's been setup through the tunnel, is subsequently closed (e.g. using SSH to login to the remote end and then logging out). * Force static libs for OpenSSL Update CMakeLists.txt to force linking with static versions of the OpenSSL libraries (libssl and libcrypto) when both static and share-object libs are available, in fashion similar to that used for Protobuf and Boost.
1 parent 9eace74 commit 2df9b59

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROJECT_SOURCE_DIR}/resources/Mess
6161
#########################################
6262
set(OPENSSL_USE_STATIC_LIBS TRUE)
6363
find_package(OpenSSL REQUIRED)
64+
include_directories(${OPENSSL_INCLUDE_DIR})
65+
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
66+
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY})
6467

6568
#########################################
6669
# Test framework dependency #
@@ -111,17 +114,17 @@ endif()
111114
include_directories(${PROJECT_SOURCE_DIR}/src)
112115

113116
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
114-
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::SSL)
115-
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::Crypto)
117+
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
118+
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
116119
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Boost_STATIC_LIBRARIES})
117120
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Protobuf_LITE_STATIC_LIBRARY})
118121
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_DL_LIBS})
119122
set_property(TARGET ${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS})
120123

121124
if(BUILD_TESTS)
122125
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_THREAD_LIBS_INIT})
123-
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::SSL)
124-
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::Crypto)
126+
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
127+
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
125128
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Boost_STATIC_LIBRARIES})
126129
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Protobuf_LITE_STATIC_LIBRARY})
127130
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_DL_LIBS})

src/TcpAdapterProxy.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,8 @@ namespace aws { namespace iot { namespace securedtunneling {
511511
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found";
512512
}
513513
connection->tcp_write_buffer_.consume(connection->tcp_write_buffer_.max_size());
514-
connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
514+
// this works on Linux x86_64 but causes a bus error on Darwin arm64, commenting it out
515+
//connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
515516
connection->socket_.close();
516517

517518
connection->on_web_socket_write_buffer_drain_complete = [&, service_id, connection_id]()
@@ -2309,4 +2310,4 @@ namespace aws { namespace iot { namespace securedtunneling {
23092310
return false;
23102311
}
23112312
}
2312-
}}}
2313+
}}}

0 commit comments

Comments
 (0)