@@ -121,20 +121,15 @@ method close*(session: QuicSession) {.async: (raises: []).} =
121121 safeClose (session.connection)
122122 await procCall P2PConnection (session).close ()
123123
124- proc getStream * (
124+ proc getStream (
125125 session: QuicSession , direction = Direction .In
126- ): Future [QuicStream ] {.async : (raises: [QuicTransportError ]).} =
126+ ): Future [QuicStream ] {.async : (raises: [CancelledError , QuicError ]).} =
127127 var stream: Stream
128- try :
129- case direction
130- of Direction .In :
131- stream = await session.connection.incomingStream ()
132- of Direction .Out :
133- stream = await session.connection.openStream ()
134- except CancelledError as exc:
135- raise (ref QuicTransportError )(msg: " cancelled getStream: " & exc.msg, parent: exc)
136- except QuicError as exc:
137- raise (ref QuicTransportError )(msg: " error in getStream: " & exc.msg, parent: exc)
128+ case direction
129+ of Direction .In :
130+ stream = await session.connection.incomingStream ()
131+ of Direction .Out :
132+ stream = await session.connection.openStream ()
138133
139134 let qs =
140135 QuicStream .new (stream, session.observedAddr, session.localAddr, session.peerId)
@@ -181,7 +176,7 @@ method newStream*(
181176.} =
182177 try :
183178 return await m.session.getStream (Direction .Out )
184- except QuicTransportError as exc:
179+ except QuicError as exc:
185180 raise newException (MuxerError , " error in newStream: " & exc.msg, exc)
186181
187182method handle * (m: QuicMuxer ): Future [void ] {.async : (raises: []).} =
@@ -192,19 +187,30 @@ method handle*(m: QuicMuxer): Future[void] {.async: (raises: []).} =
192187 trace " finished handling stream"
193188 doAssert (chann.closed, " connection not closed by handler!" )
194189
195- try :
196- while not m.session.atEof:
197- let stream = await m.session.getStream (Direction .In )
198- asyncSpawn handleStream (stream)
199- except QuicTransportError as exc:
200- trace " Exception in quic handler" , msg = exc.msg
190+ while not m.session.atEof:
191+ let stream =
192+ try :
193+ await m.session.getStream (Direction .In )
194+ except CancelledError :
195+ # keep handling, until connection is closed
196+ continue
197+ except QuicError as exc:
198+ if exc.msg == " connection closed" :
199+ # stop handling, connection was closed
200+ break
201+ else :
202+ # keep handling, until connection is closed.
203+ # this stream failed but we need to keep handling for other streams.
204+ trace " QuicMuxer.handler got error while opening stream" , msg = exc.msg
205+ continue
206+ asyncSpawn handleStream (stream)
201207
202208method close * (m: QuicMuxer ) {.async : (raises: []).} =
203209 try :
204210 await m.session.close ()
205211 if not isNil (m.handleFut):
206212 m.handleFut.cancelSoon ()
207- except CatchableError as exc :
213+ except CatchableError :
208214 discard
209215
210216# Transport
0 commit comments