Skip to content

Commit

Permalink
Fix two QUIC issues:
Browse files Browse the repository at this point in the history
  1) We treated stream reset like connection terminated, which
     is just wrong.  We should send EOF to the stream but leave
     the connection alone.

  2) When we got an unexpected EOF on a stream, we raised the
     exception in the wrong place, killing the QUIC connection
     but leaving the stream blocked.  Now we deliver the exception
     to the stream and don't kill the connection.
  • Loading branch information
rthalley committed Oct 22, 2023
1 parent 1957961 commit 954856b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 6 additions & 3 deletions dns/quic/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,14 @@ async def _handle_events(self):
await stream._add_input(event.data, event.end_stream)
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
self._handshake_complete.set()
elif isinstance(
event, aioquic.quic.events.ConnectionTerminated
) or isinstance(event, aioquic.quic.events.StreamReset):
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
self._done = True
self._receiver_task.cancel()
elif isinstance(event, aioquic.quic.events.StreamReset):
stream = self._streams.get(event.stream_id)
if stream:
await stream._add_input(b"", True)

count += 1
if count > 10:
# yield
Expand Down
5 changes: 4 additions & 1 deletion dns/quic/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def _encapsulate(self, datagram):

def _common_add_input(self, data, is_end):
self._buffer.put(data, is_end)
return self._expecting > 0 and self._buffer.have(self._expecting)
try:
return self._expecting > 0 and self._buffer.have(self._expecting)
except UnexpectedEOF:
return True

def _close(self):
self._connection.close_stream(self._stream_id)
Expand Down
9 changes: 6 additions & 3 deletions dns/quic/_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ def _handle_events(self):
stream._add_input(event.data, event.end_stream)
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
self._handshake_complete.set()
elif isinstance(
event, aioquic.quic.events.ConnectionTerminated
) or isinstance(event, aioquic.quic.events.StreamReset):
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
with self._lock:
self._done = True
elif isinstance(event, aioquic.quic.events.StreamReset):
with self._lock:
stream = self._streams.get(event.stream_id)
if stream:
stream._add_input(b"", True)

def write(self, stream, data, is_end=False):
with self._lock:
Expand Down
8 changes: 5 additions & 3 deletions dns/quic/_trio.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ async def _handle_events(self):
await stream._add_input(event.data, event.end_stream)
elif isinstance(event, aioquic.quic.events.HandshakeCompleted):
self._handshake_complete.set()
elif isinstance(
event, aioquic.quic.events.ConnectionTerminated
) or isinstance(event, aioquic.quic.events.StreamReset):
elif isinstance(event, aioquic.quic.events.ConnectionTerminated):
self._done = True
self._socket.close()
elif isinstance(event, aioquic.quic.events.StreamReset):
stream = self._streams.get(event.stream_id)
if stream:
await stream._add_input(b"", True)
count += 1
if count > 10:
# yield
Expand Down

0 comments on commit 954856b

Please sign in to comment.