Return transport socket errors as nano::io_result instead of throwing them (#5286) * Remove the unused block_deserializer and throw_if_error block_deserializer read blocks off a socket for the legacy bootstrap and nothing constructs it any more. throw_if_error has no callers. * Add nano::io_result and a completion token that awaits into it nano::io_result<T> is boost::system::result<T>: the value of an I/O operation or the error code it failed with, with nano::io_success () for an operation that produces no value. nano::async::as_result adapts an asio completion token so the operation completes with one nano::io_result instead of an error code and a value, and nano::async::use_result is that adapter applied to use_awaitable. Awaiting an operation with it returns a failure as a value instead of throwing it. Cancelling the awaiting coroutine still cancels the operation, which then completes with operation_aborted. The helpers live in nano/lib/io_result.hpp, included from async.hpp. * Return nano::io_result from the tcp_socket coroutines co_connect, co_read and co_write return nano::io_result<void> and await the asio operations with use_result. A read or write completes only once the whole buffer is transferred, so they no longer report a byte count: a completed read is checked to have filled the buffer inside the socket, and the callback and blocking adapters hand on just the error code. The tests stop asserting the counts. tcp_channel::send_one returns the write's result. tcp_server adapts to the new API and still turns a failed read or write into an exception for now. The failed connect log line now prints the error code, where it printed the local endpoint. * Return socket errors from tcp_server instead of throwing them A peer that disconnects ends every connection, so a failed read or handshake write is the normal way a server stops, not an exception. The handshake functions return nano::io_result<handshake_status>, receive_message an io_result of the parsed message, read_socket an io_result of the buffer view, and the handshake senders and run_realtime an io_result<void>. The new run () performs the handshake and then the realtime loop. start_impl reports a failed run once, with the same stat and log line as before, and its catch is left to asio's cancellation, which still throws operation_aborted at the next co_await of a cancelled coroutine. A new test has a peer close a realtime connection; handshake_incomplete_message already covers a peer that hangs up during the handshake. * Return accept and connect errors from tcp_listener instead of throwing accept_socket and connect_socket await with use_result and return an io_result of the connected socket together with its remote endpoint, read through the error code overload since the peer may already be gone. run () and connect_impl lose their try blocks, and accept_one takes the endpoint instead of reading it with the throwing overload. A socket built from a connected one reads its endpoints best effort, as a connecting socket already does. Stopping the listener cancels its pending accept, which now ends the accept loop instead of being counted as an accept error. * Rename the channel send callback to send_callback channel::callback_t did not say what it is for. It is the completion of a send, so it becomes nano::transport::send_callback next to connect_callback in the transport common header, and tcp_channel_queue drops its own copy of the same alias. * Count a sent handshake response once send_handshake_response incremented handshake_response before the write and again after it, so every response was counted twice. It now counts only a response that was sent, like the query side does with handshake. A new test completes one handshake on a connection a peer opened and one on a connection the node opened to a listening peer, and checks that each message the node sent is counted once: only its response on the first, its query and its response on the second. * Remove the legacy bootstrap switch from the transport Nothing calls tcp_server::to_bootstrap_connection any more, so no socket becomes a bootstrap socket and the handshake never produces the bootstrap status. The method, the status, socket_type::bootstrap and tcp_listener::bootstrap_count go, and the monitor drops its bootstrap peer count, which was always zero. The bootstrap_connections_max config key only fed that switch and is retired: it is no longer written or read, and a config file that still sets it loads as before, since unknown keys are ignored. * Remove unused socket helpers and the obsolete socket tests tcp_socket::co_connect has no callers; the callback and blocking connect adapters stay. The socket_functions subnet helpers and their address multimap were only used by their own tests. The two disabled socket tests checked a write queue the socket no longer has. * Test the listener's attempt limit and connect timeout Two listener paths had no test. A connect to an address with an attempt already in flight is refused at the per IP attempt limit and counted, and goes through again after the purge. An unanswered connect is cancelled at the connect timeout, which reports the cancellation to its callback and counts the timeout; that test needs an address that swallows connects and skips itself where the network refuses them at once. * Test replayed and empty handshakes Two server paths had no test. A handshake query replayed on a realtime connection is counted as ignored, gets no reply and leaves the connection running for the messages behind it. A handshake with neither query nor response is counted as a handshake error and aborts the handshake. * Rework the socket timeout tests socket_timeout.connect set io_timeout, which does not apply to connects, and relied on 10.255.254.253 swallowing the connect, with its 5 to 6 s timeout racing a 6 s wait. A socket's connect timeout runs from its creation, so the test now lowers connect_timeout and lets a socket that never connects time out, without any network. The other timeout tests take the test peer's listener as the far end instead of five copies of the acceptor setup, use the blocking adapters instead of nested callbacks, and assert exact counts, including the tcp_socket_timeout reason, since the far end is not a node socket and the node's socket is the only one counted. The silence test, renamed from socket.disconnection_of_silent_connections, waits 2 s instead of 5, and the two _overlapped tests are renamed for what they check: a timeout on the read or write after one that succeeded. * Retire the unused legacy bootstrap config keys bootstrap_connections and bootstrap_initiator_threads configured the outbound connections and initiator threads of the legacy bootstrap, which no longer exists, and nothing reads them. They are no longer written or read; a config file that still sets them loads as before, since unknown keys are ignored. The bootstrap_connections thread role, which no thread takes any more, goes with them. * Close a peer's connection on an unexpected exception instead of aborting The server, channel and socket checkup tasks and the socket's callback adapters now await their coroutine through nano::async::settle, which reports how it ended instead of letting an exception through. An exception other than a cancellation is logged at error level and debug asserted, and the connection closes as on any other error. The server and channel used to release assert, and the checkup let the exception escape, leaving the socket open without its timeouts. The listener's accept loop keeps its release assert, as it runs once per node rather than once per peer. # Conflicts: # nano/node/transport/tcp_channel.cpp * Drop the byte count from the channel send callback No caller read it, and after a failed write it could only be a partial count. The callback now reports just the outcome: an empty error code means the whole message was written. # Conflicts: # nano/core_test/tcp_channel.cpp # nano/node/transport/tcp_channel.cpp * Return nano::io_result from the channel's sending loop The sending loop reported a failed write with a plain return, so the reason sending stopped never reached start_sending. It now returns nano::io_result<void>, like the server's run, and start_sending logs the error at debug level. * Run a connection's server and channel on its socket's strand The socket, its server and its channel each ran on a strand of their own, so every read and write hopped from the caller's strand to the socket's and back. The server and the channel now run on the socket's strand, and co_read and co_write assert that strand instead of dispatching to it. The callback and blocking adapters still spawn the operation onto the strand. * Keep the code of a std::system_error in nano::async::settle boost::system::system_error does not derive from std::system_error, so a standard library system error fell through to the handler for exceptions without a code and settled as error_common::exception. It now settles with its own code, still as unexpected: asio throws the boost type, so a std::system_error is never a cancellation. * Take the remote endpoint of a connected socket from its listener The listener reads the remote endpoint of an accepted or connected socket and gives the connection up when that read fails. The tcp_socket constructor then read it a second time with the error ignored, so a peer that reset the connection in between left the socket, its channel and the logs with an unspecified address while the listener's index held the real one. The constructor now takes the endpoint the listener read. The new tcp_socket test builds a socket over a connection its peer has already reset, where the endpoint can no longer be read, and checks that the socket reports the one it was given. * Fix Asio initiation and token forwarding in as_result Pass the original initiator through async_initiate and preserve its I/O executor for stacked adapters. Forward the inner token with the outer adapter's value category so named callbacks can be reused. Construct io_result from the declared completion signature and forward the wrapped handler's associated properties and continuation hook.
__________
Type: commit
Hash: c3793c96c3c69dac0d884d144e52697c9918cb0f
Created: yesterday
__________
gr0v1ty/nano-node:c3793c96c3c69dac0d884d144e52697c9918cb0f
| Test Case | Status | Duration | Median Deviation | Log | Graph |
|---|---|---|---|---|---|
| 5n4pr_conf_10k_bintree | PASS | 103 s | -2.0 s | GitHub job logs | Show |
| 5n4pr_conf_10k_change | PASS | 132 s | 10.0 s | GitHub job logs | Show |
| 5n4pr_conf_change_dependant | PASS | 109 s | 0.0 s | GitHub job logs | - |
| 5n4pr_conf_change_independant | PASS | 96 s | -10.0 s | GitHub job logs | - |
| 5n4pr_conf_send_dependant | PASS | 121 s | 13.0 s | GitHub job logs | - |
| 5n4pr_conf_send_independant | PASS | 110 s | 0.0 s | GitHub job logs | - |
| 5n4pr_rocks_10k_bintree | PASS | 105 s | 0.0 s | GitHub job logs | - |
| 5n4pr_rocks_10k_change | PASS | 157 s | 5.0 s | GitHub job logs | - |