mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
todo: handle timeout
This commit is contained in:
@ -176,8 +176,6 @@ class MplexStream(IMuxedStream):
|
|||||||
Closing a stream closes it for writing and closes the remote end for
|
Closing a stream closes it for writing and closes the remote end for
|
||||||
reading but allows writing in the other direction.
|
reading but allows writing in the other direction.
|
||||||
"""
|
"""
|
||||||
# TODO error handling with timeout
|
|
||||||
|
|
||||||
async with self.close_lock:
|
async with self.close_lock:
|
||||||
if self.event_local_closed.is_set():
|
if self.event_local_closed.is_set():
|
||||||
return
|
return
|
||||||
@ -185,8 +183,17 @@ class MplexStream(IMuxedStream):
|
|||||||
flag = (
|
flag = (
|
||||||
HeaderTags.CloseInitiator if self.is_initiator else HeaderTags.CloseReceiver
|
HeaderTags.CloseInitiator if self.is_initiator else HeaderTags.CloseReceiver
|
||||||
)
|
)
|
||||||
# TODO: Raise when `muxed_conn.send_message` fails and `Mplex` isn't shutdown.
|
|
||||||
await self.muxed_conn.send_message(flag, None, self.stream_id)
|
try:
|
||||||
|
with trio.fail_after(5): # timeout in seconds
|
||||||
|
await self.muxed_conn.send_message(flag, None, self.stream_id)
|
||||||
|
except trio.TooSlowError:
|
||||||
|
raise TimeoutError("Timeout while trying to close the stream")
|
||||||
|
except MuxedConnUnavailable:
|
||||||
|
if not self.muxed_conn.event_shutting_down.is_set():
|
||||||
|
raise RuntimeError(
|
||||||
|
"Failed to send close message and Mplex isn't shutting down"
|
||||||
|
)
|
||||||
|
|
||||||
_is_remote_closed: bool
|
_is_remote_closed: bool
|
||||||
async with self.close_lock:
|
async with self.close_lock:
|
||||||
|
|||||||
Reference in New Issue
Block a user