Skip to content

Commit

Permalink
do not swallow FIN frames without data, fix #438
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Jan 1, 2024
1 parent ac18ff6 commit 6157d97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/aioquic/quic/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def get_frame(
if self._pending_eof:
# FIN only
self._pending_eof = False
if self._buffer_start == self._buffer_fin:
self.is_finished = True
return QuicStreamFrame(fin=True, offset=self._buffer_fin)

self.buffer_is_empty = True
Expand Down Expand Up @@ -265,8 +267,8 @@ def on_data_delivery(
self._buffer_start += size
del self._buffer[:size]

if self._buffer_start == self._buffer_fin:
# all date up to the FIN has been ACK'd, we're done sending
if self._buffer_start == self._buffer_fin and not self._pending_eof:
# all data up to the FIN has been ACK'd, we're done sending
self.is_finished = True
else:
if stop > start:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,29 @@ def test_sender_fin_only(self):
self.assertIsNone(frame)
self.assertTrue(stream.sender.buffer_is_empty)

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")

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

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

# sending FIN transitions to finished
frame = stream.sender.get_frame(8)
self.assertEqual(frame.data, b"")
self.assertTrue(frame.fin)
self.assertEqual(frame.offset, 4)
self.assertTrue(stream.sender.is_finished)

def test_sender_fin_only_despite_blocked(self):
stream = QuicStream()

Expand Down

0 comments on commit 6157d97

Please sign in to comment.