File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
libp2p/stream_muxer/mplex Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -176,17 +176,24 @@ async def close(self) -> None:
176
176
Closing a stream closes it for writing and closes the remote end for
177
177
reading but allows writing in the other direction.
178
178
"""
179
- # TODO error handling with timeout
180
-
181
179
async with self .close_lock :
182
180
if self .event_local_closed .is_set ():
183
181
return
184
182
185
183
flag = (
186
184
HeaderTags .CloseInitiator if self .is_initiator else HeaderTags .CloseReceiver
187
185
)
188
- # TODO: Raise when `muxed_conn.send_message` fails and `Mplex` isn't shutdown.
189
- await self .muxed_conn .send_message (flag , None , self .stream_id )
186
+
187
+ try :
188
+ with trio .fail_after (5 ): # timeout in seconds
189
+ await self .muxed_conn .send_message (flag , None , self .stream_id )
190
+ except trio .TooSlowError :
191
+ raise TimeoutError ("Timeout while trying to close the stream" )
192
+ except MuxedConnUnavailable :
193
+ if not self .muxed_conn .event_shutting_down .is_set ():
194
+ raise RuntimeError (
195
+ "Failed to send close message and Mplex isn't shutting down"
196
+ )
190
197
191
198
_is_remote_closed : bool
192
199
async with self .close_lock :
You can’t perform that action at this time.
0 commit comments