End a channel's bandwidth wait once its socket closes (#5301) * End a channel's bandwidth wait once its socket closes A channel short of outbound bandwidth kept waiting for the limiter after its socket closed, until the bandwidth returned or the channel was cleaned up, and only then failed the send with a write to the closed socket. The wait is now its own coroutine, awaited only when the allocation left over from earlier sends does not cover the next one, and it fails with operation_aborted once the socket closes. A cancelled wait fails the same way. Closing a channel cancels its sending coroutine before the socket closes, and nano::async::sleep_for swallowed that cancellation, so the coroutine's next wait threw and the send it was waiting for was never reported. sleep_for now returns a nano::io_result that holds operation_aborted when it was cancelled. send_one checks the allocation again before taking the send's bytes out of it. A shortfall there is a bug: it debug asserts and fails the send rather than let it past the limiter. It returns at the first failure, and the sending loop reports each send's outcome to its callback at one place. The allocation is a plain size_t, since only the sending coroutine on the socket's strand touches it. The new tcp_channel tests hold one send in the bandwidth wait of a channel the node has not registered, then close its socket or the channel, and check the send's callback runs once with operation_aborted and nothing is written. A new async test covers both results of sleep_for. * Make the outbound bandwidth allocation a tcp setting A channel takes outbound bandwidth from the limiter in larger amounts so that not every send has to ask it. The amount was a hard coded 128 KiB; it is now node.tcp.bandwidth_allocation with the same default. The wait takes at least what the send still lacks, so an allocation smaller than a message, or 0, still makes progress instead of asking the limiter forever. A new tcp_channel test sends with an allocation of 0. * Keep a channel's bandwidth allocation with the limiter that granted it Generic traffic and bootstrap responses are charged to separate limiters, but a channel kept one allocation for both. Bandwidth left over from an allocation the generic limiter granted was spent on bootstrap responses, and the other way round, without asking the limiter that traffic is charged to. A larger bandwidth_allocation setting would widen that. The limiters now have a name, nano::bandwidth_limit_type, and to_bandwidth_limit_type says which one a traffic type is charged to. The limiter selects by it and a channel keeps one allocation per limiter. The new tcp_channel test leaves a channel with a generic allocation, then checks that a bootstrap response waits for its own limiter. # Conflicts: # nano/node/transport/tcp_channel.cpp # Conflicts: # nano/node/transport/tcp_channel.cpp * Report a channel's send when its cancellation is thrown A bandwidth wait's timer that expires just before the channel is closed can no longer be cancelled, so the wait resumes with success. The coroutine is cancelled all the same, and its next wait throws operation_aborted past the sending loop, which never ran the send's callback. The sending loop now catches a cancellation thrown out of send_one and reports it to the callback like one that was returned. Any other exception still reaches settle as unexpected. The new tcp_channel test holds the channel's strand until the wait's timer has expired and closes the channel, so the cancellation arrives too late to cancel the timer. Without the catch it failed on both backends, with the callback never run.
__________
Type: commit
Hash: c94d7c15f9b942afe8c55eb79a29ac8cdbbf9f16
Created: yesterday
__________
gr0v1ty/nano-node:c94d7c15f9b942afe8c55eb79a29ac8cdbbf9f16
| Test Case | Status | Duration | Median Deviation | Log | Graph |
|---|---|---|---|---|---|
| No test results available yet. Check the GitHub test run for job status and logs. | |||||