Skip to content

Commit

Permalink
Fix bus error from boost socket.shutdown in tcp_socket_error() and li…
Browse files Browse the repository at this point in the history
…nk 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.
  • Loading branch information
dbouras authored Jun 27, 2024
1 parent 9eace74 commit 2df9b59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROJECT_SOURCE_DIR}/resources/Mess
#########################################
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY})
string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY})

#########################################
# Test framework dependency #
Expand Down Expand Up @@ -111,17 +114,17 @@ endif()
include_directories(${PROJECT_SOURCE_DIR}/src)

target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::SSL)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} OpenSSL::Crypto)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Boost_STATIC_LIBRARIES})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Protobuf_LITE_STATIC_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_DL_LIBS})
set_property(TARGET ${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS})

if(BUILD_TESTS)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::SSL)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} OpenSSL::Crypto)
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_SSL_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Boost_STATIC_LIBRARIES})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Protobuf_LITE_STATIC_LIBRARY})
target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_DL_LIBS})
Expand Down
5 changes: 3 additions & 2 deletions src/TcpAdapterProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ namespace aws { namespace iot { namespace securedtunneling {
BOOST_LOG_SEV(this->log, info) << "Disconnecting... remote endpoint not found";
}
connection->tcp_write_buffer_.consume(connection->tcp_write_buffer_.max_size());
connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
// this works on Linux x86_64 but causes a bus error on Darwin arm64, commenting it out
//connection->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_receive);
connection->socket_.close();

connection->on_web_socket_write_buffer_drain_complete = [&, service_id, connection_id]()
Expand Down Expand Up @@ -2309,4 +2310,4 @@ namespace aws { namespace iot { namespace securedtunneling {
return false;
}
}
}}}
}}}

0 comments on commit 2df9b59

Please sign in to comment.