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

Do not swallow FIN frames without data #439

Closed
wants to merge 3 commits into from
Closed

Conversation

mhils
Copy link
Contributor

@mhils mhils commented Jan 1, 2024

This PR fixes #438. Thanks for your hard work on aioquic! 🍰

Copy link

codecov bot commented Jan 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ac18ff6) 100.00% compared to head (5c3b466) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #439   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         4868      4867    -1     
=========================================
- Hits          4868      4867    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/aioquic/quic/stream.py Outdated Show resolved Hide resolved
@jlaine
Copy link
Contributor

jlaine commented Jan 6, 2024

Thanks so much for digging into this, it does look like a tricky situation! Double thanks for providing a unit test :)

I haven't looked at this part of the code, so my apologies if my comment is incorrect, but something doesn't feel right about the stream ending in response to use sending something as opposed to receiving an ACK.

@mhils
Copy link
Contributor Author

mhils commented Jan 6, 2024

See my answer above. One more clarification: This is the stream sender ending, not the entire stream. The stream itself is not necessarily finished (the stream receiver may still be active).

@jlaine
Copy link
Contributor

jlaine commented Jan 6, 2024

See my answer above. One more clarification: This is the stream sender ending, not the entire stream. The stream itself is not necessarily finished (the stream receiver may still be active).

Right, I'm quite clear that we're only talking about the sender part, but let's take the case of a unidirectional stream on which we'll only be sending. In this case, when the sender part finishes, the whole stream finishes and we discard its state.

I agree with the additional condition you added (and not self._pending_eof) in on_data_delivery : this is indeed needed.

What I don't agree with is the change in get_frame: simply sending out the FIN doesn't mean we're done, we still want on_data_delivery to inform us the FIN has actually been acknowledged.

@jlaine
Copy link
Contributor

jlaine commented Jan 6, 2024

If we remove the change to get_frame, this is how the test would look:

    def test_sender_fin_then_ack(self):
        stream = QuicStream()

        # send some data
        stream.sender.write(b"data")
        frame = stream.sender.get_frame(8)
        self.assertEqual(frame.data, b"data")

        # request EOF
        stream.sender.write(b"", end_stream=True)
        self.assertFalse(stream.sender.buffer_is_empty)

        # receive acknowledgement for data
        stream.sender.on_data_delivery(QuicDeliveryState.ACKED, 0, 4)
        self.assertFalse(stream.sender.is_finished)

        # send EOF
        frame = stream.sender.get_frame(8)
        self.assertEqual(frame.data, b"")
        self.assertTrue(frame.fin)
        self.assertEqual(frame.offset, 4)
        self.assertFalse(stream.sender.is_finished)

        # receive acknowledgement for EOF
        stream.sender.on_data_delivery(QuicDeliveryState.ACKED, 4, 4)
        self.assertTrue(stream.sender.is_finished)

@mhils
Copy link
Contributor Author

mhils commented Jan 6, 2024

What I don't agree with is the change in get_frame: simply sending out the FIN doesn't mean we're done, we still want on_data_delivery to inform us the FIN has actually been acknowledged.

D'oh! I totally missed that mechanic. Thanks for pointing that out, I've just pushed a fix that removes the premature is_finished assignment.

@jlaine
Copy link
Contributor

jlaine commented Jan 6, 2024

If you don't mind I think I need to think some more about whether we're 100% OK now. I'm wondering whether there isn't yet another pitfall here where we have sent out the FIN, but the receiver only ACK'd the data but not the FIN. In this situation, simply looking at the offset which was acknowledged doesn't tell us whether the FIN was ACK'd, or am I wrong?

This might mean changing the on_data_delivery signature to explicitly convey whether the ACK'd frame had the FIN flag set, or even adding an on_fin_delivery method.

@mhils
Copy link
Contributor Author

mhils commented Jan 7, 2024

Right - I naively expected the connection to handle retransmission, but if that's handled by QuicStreamSender itself then we need a way to detect FIN acks + new state that tracks that. This also needs to handle the case that the ACK for the FIN is not the last ACK for the stream (i.e. there's other data still in flight).

@mhils mhils marked this pull request as draft January 7, 2024 00:08
jlaine added a commit to jlaine/aioquic that referenced this pull request Jan 7, 2024
@jlaine
Copy link
Contributor

jlaine commented Jan 7, 2024

Superseeded by #441

@jlaine jlaine closed this Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FINs are swallowed if data is fully ACKed
2 participants