Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix close_write() being called too eagerly #2840

Merged
merged 5 commits into from
Oct 7, 2022

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Oct 7, 2022

Fix #2831

The problem turned out to be very stupid:
Calling close_write() is just a shortcut for outgoing_buffer = None.
So you're supposed to call close_write() when you have nothing more to write.

The problem is that we're calling write_from_vec_deque(data), which transfers data from data to outgoing_buffer. Then we realize that data is empty (because it's been entirely copied to outgoing_buffer), and call close_write(). This sets outgoing_buffer to None and thus erases the data that we've just copied.

Instead, we now call close_write at the next iteration (when the data will have been extracted out), which is what you're supposed to do.

Additionally, as a safety measure, I've replaced close_write with close_write_if_empty. I think that close_write is too dangerous. There's never a situation where you would want to cancel sending data that you've already queued for writing.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
         +64 ┊ smoldot::libp2p::connection::established::substream::Substream<TNow,TRqUd,TNotifUd>::read_write2::h257d3eece62d937b
         +49 ┊ smoldot::libp2p::read_write::ReadWrite<TNow>::close_write_if_empty::hebd5966bcd84121a
          +2 ┊ smoldot::libp2p::collection::multi_stream::MultiStreamConnectionTask<TNow,TSubId>::substream_read_write::hb5abbd2ac799eeef
          +1 ┊ smoldot::libp2p::collection::single_stream::SingleStreamConnectionTask<TNow>::read_write::h42c5a34b21df456e
          +1 ┊ smoldot::libp2p::connection::established::single_stream::SingleStream<TNow,TRqUd,TNotifUd>::read_write::h38cd277718fc88b9
        +216 ┊ Σ [5 Total Rows]

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Oct 7, 2022
@mergify mergify bot merged commit bffd3ad into paritytech:main Oct 7, 2022
@tomaka tomaka deleted the fix-close-write-too-eager branch October 7, 2022 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem in identify protocol
1 participant