handle dial cancellation (#113)

This commit is contained in:
vladopajic
2025-09-04 14:20:59 +02:00
committed by GitHub
parent fe02a9a5e3
commit 2c5066170c
2 changed files with 13 additions and 2 deletions

View File

@@ -119,7 +119,8 @@ proc dial*(
try:
connection.startHandshake()
await connection.waitForHandshake()
except TimeOutError as exc:
except CatchableError as exc:
# whatever error happens we need to destroy tlsBackend to free resources
tlsBackend.destroy()
raise exc

View File

@@ -173,7 +173,17 @@ proc waitForHandshake*(
let errFut = connection.quic.error.waitEvents(key)
let timeoutFut = connection.quic.timeout.wait()
let handshakeFut = connection.quic.handshake.wait()
let raceFut = await race(handshakeFut, timeoutFut, errFut)
let raceFut =
try:
await race(handshakeFut, timeoutFut, errFut)
except CancelledError as e:
let connCloseFut = connection.close()
handshakeFut.cancelSoon()
errFut.cancelSoon()
timeoutFut.cancelSoon()
await connCloseFut
raise e
if raceFut == timeoutFut:
let connCloseFut = connection.close()
errFut.cancelSoon()