From f8e685d442ce631527b6eddb87b4ee64606f0620 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:18:41 -0500 Subject: [PATCH] always set socket to blocking mode before read_message_with_fds's recvmsg() --- .../webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp b/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp index 15353d2e64..da1ee268b2 100644 --- a/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp +++ b/libraries/chain/webassembly/runtimes/eos-vm-oc/ipc_helpers.cpp @@ -7,6 +7,16 @@ static constexpr size_t max_message_size = 8192; static constexpr size_t max_num_fds = 4; std::tuple> read_message_with_fds(boost::asio::local::datagram_protocol::socket& s) { + // read_message_with_fds() is intended to be blocking, and sockets it is used with are never explicitly set to non-blocking mode. + // But when doing an async_wait() on an asio socket, asio will set the underlying file descriptor to non-blocking mode. + // It's not clear why, but in some cases after async_wait() indicates readiness, a recvmsg() on the socket can fail with + // EAGAIN if the file descriptor is still in non-blocking mode (as asio had set it to). + // Always set the file descriptor to blocking mode before performing the recvmsg() + boost::system::error_code ec; + s.native_non_blocking(false, ec); + if(ec) + wlog("Failed to set socket's native blocking mode"); + return read_message_with_fds(s.native_handle()); }