Skip to content

Commit 2f6c801

Browse files
committed
fix closed
1 parent 332e703 commit 2f6c801

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

libp2p/transports/quictransport.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ method closeImpl*(stream: QuicStream) {.async: (raises: []).} =
111111

112112
# Session
113113
type QuicSession* = ref object of P2PConnection
114-
connection*: QuicConnection
114+
connection: QuicConnection
115115
streams: seq[QuicStream]
116116

117+
method closed*(session: QuicSession): bool {.raises: [].} =
118+
procCall P2PConnection(session).isClosed or session.connection.isClosed
119+
117120
method close*(session: QuicSession) {.async: (raises: []).} =
118121
for s in session.streams:
119122
await s.close()
120-
if session != nil:
121-
session.connection.close()
123+
session.connection.close()
122124
await procCall P2PConnection(session).close()
123125

124126
proc getStream(
@@ -187,7 +189,7 @@ method handle*(m: QuicMuxer): Future[void] {.async: (raises: []).} =
187189
trace "finished handling stream"
188190
doAssert(stream.closed, "connection not closed by handler!")
189191

190-
while not (m.session.atEof or m.session.connection.isClosed):
192+
while not (m.session.atEof or m.session.closed):
191193
try:
192194
let stream = await m.session.getStream(Direction.In)
193195
asyncSpawn handleStream(stream)

tests/transports/testquic.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ suite "Quic transport":
8181
# validates the certificate, it will close the connection
8282
# hence why a sleep is necessary
8383
await sleepAsync(100.milliseconds)
84-
let isClosed = (cast[QuicSession](conn)).connection.isClosed
85-
check:
86-
isClosed
84+
check (cast[QuicSession](conn)).closed()
8785
await client.stop()
8886

8987
await runClient()

0 commit comments

Comments
 (0)