fix: succesfull echo

This commit is contained in:
Akash Mondal
2025-06-30 12:58:11 +00:00
committed by lla-dane
parent bbe632bd85
commit 8f0cdc9ed4
5 changed files with 26 additions and 19 deletions

View File

@ -1,6 +1,7 @@
from enum import (
Enum,
)
import inspect
import trio
@ -163,20 +164,25 @@ class NetStream(INetStream):
data = await self.muxed_stream.read(n)
return data
except MuxedStreamEOF as error:
print("NETSTREAM: READ ERROR, RECEIVED EOF")
async with self._state_lock:
if self.__stream_state == StreamState.CLOSE_WRITE:
self.__stream_state = StreamState.CLOSE_BOTH
print("NETSTREAM: READ ERROR, REMOVING STREAM")
await self._remove()
elif self.__stream_state == StreamState.OPEN:
print("NETSTREAM: READ ERROR, NEW STATE -> CLOSE_READ")
self.__stream_state = StreamState.CLOSE_READ
raise StreamEOF() from error
except MuxedStreamReset as error:
print("NETSTREAM: READ ERROR, MUXED STREAM RESET")
async with self._state_lock:
if self.__stream_state in [
StreamState.OPEN,
StreamState.CLOSE_READ,
StreamState.CLOSE_WRITE,
]:
print("NETSTREAM: READ ERROR, NEW STATE -> RESET")
self.__stream_state = StreamState.RESET
await self._remove()
raise StreamReset() from error
@ -210,6 +216,8 @@ class NetStream(INetStream):
async def close(self) -> None:
"""Close stream for writing."""
print("NETSTREAM: CLOSING STREAM, CURRENT STATE: ", self.__stream_state)
print("CALLED BY: ", inspect.stack()[1].function)
async with self._state_lock:
if self.__stream_state in [
StreamState.CLOSE_BOTH,
@ -229,6 +237,7 @@ class NetStream(INetStream):
async def reset(self) -> None:
"""Reset stream, closing both ends."""
print("NETSTREAM: RESETING STREAM")
async with self._state_lock:
if self.__stream_state == StreamState.RESET:
return

View File

@ -966,7 +966,7 @@ class QUICConnection(IRawConnection, IMuxedConn):
self, event: events.ConnectionTerminated
) -> None:
"""Handle connection termination."""
logger.debug(f"QUIC connection terminated: {event.reason_phrase}")
print(f"QUIC connection terminated: {event.reason_phrase}")
# Close all streams
for stream in list(self._streams.values()):

View File

@ -360,10 +360,6 @@ class QUICStream(IMuxedStream):
return
try:
# Signal read closure to QUIC layer
self._connection._quic.reset_stream(self._stream_id, error_code=0)
await self._connection._transmit()
self._read_closed = True
async with self._state_lock:
@ -590,6 +586,7 @@ class QUICStream(IMuxedStream):
exc_tb: TracebackType | None,
) -> None:
"""Exit the async context manager and close the stream."""
print("Exiting the context and closing the stream")
await self.close()
def set_deadline(self, ttl: int) -> bool: