Commit a928b44b authored by Dominik Charousset's avatar Dominik Charousset

Make sure data is shipped before closing a socket

parent e6d467ca
...@@ -9,6 +9,9 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -9,6 +9,9 @@ is based on [Keep a Changelog](https://keepachangelog.com).
- Fix flow setup for servers that use `web_socket::with`. This bug caused - Fix flow setup for servers that use `web_socket::with`. This bug caused
servers to immediately abort incoming connection (#1402). servers to immediately abort incoming connection (#1402).
- Make sure that a protocol stack ships pending data before closing a socket.
This bug prevented clients from receiving error messages from servers if the
server shuts down immediately after writing the message.
## [0.19.0] - 2023-04-17 ## [0.19.0] - 2023-04-17
......
...@@ -214,16 +214,16 @@ void transport::handle_buffered_data() { ...@@ -214,16 +214,16 @@ void transport::handle_buffered_data() {
auto delta = bytes.subspan(delta_offset_); auto delta = bytes.subspan(delta_offset_);
auto consumed = up_->consume(bytes, delta); auto consumed = up_->consume(bytes, delta);
if (consumed < 0) { if (consumed < 0) {
// Negative values indicate that the application encountered an // Negative values indicate that the application wants to close the
// unrecoverable error. // socket. We still make sure to send any pending data before closing.
up_->abort(make_error(caf::sec::runtime_error, "consumed < 0")); up_->abort(make_error(caf::sec::runtime_error, "consumed < 0"));
parent_->deregister(); parent_->deregister_reading();
return; return;
} else if (static_cast<size_t>(consumed) > n) { } else if (static_cast<size_t>(consumed) > n) {
// Must not happen. An application cannot handle more data then we pass // Must not happen. An application cannot handle more data then we pass
// to it. // to it.
up_->abort(make_error(sec::logic_error, "consumed > buffer.size")); up_->abort(make_error(sec::logic_error, "consumed > buffer.size"));
parent_->deregister(); parent_->deregister_reading();
return; return;
} else if (consumed == 0) { } else if (consumed == 0) {
if (next_) { if (next_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment