Open tersec opened 3 months ago
Slightly less minimized version, showing the uinttest2
aspects more explicitly:
import ./asyncloop
import unittest2
proc connect(): Future[int] {.
async: (raw: true, raises: [ValueError]).} =
var retFuture = newFuture[int]("stream.transport.connect")
retFuture.fail(newException(ValueError,
"connect local address domain is not equal to target address domain"))
return retFuture
proc closeWait(transp: int): Future[void] {.async: (raw: true, raises: []).} =
var retFuture = newFuture[void]("stream.transport.join")
retFuture.complete()
return retFuture
type
TcpTransport = object
client: int
proc new(T: typedesc[TcpTransport]): T =
return default(TcpTransport)
method stop(self: TcpTransport) {.async.} =
discard await allFinished(@[self.client.closeWait()])
var stub: TcpTransport
suite "Tor transport":
setup:
stub = TcpTransport.new()
teardown:
waitFor stub.stop()
test "test start and dial using ipv4":
# asyncTest
waitFor((
proc() {.async.} =
discard await connect()
)())
But see above, unittest
and its fun use of gcsafe
and threadvar
are not required to repro this.
The problem is not in unittest2
, because last example is impossible to reproduce for me, but initial one is possible to reproduce on Linux and Windows with Nim 1.6.18.
I could also confirm that this (asyncdispatch version)
import asyncdispatch
proc t(): Future[int] =
var retFuture = newFuture[int]("")
retFuture.fail(newException(ValueError, ""))
return retFuture
proc m(transp: int): Future[void] =
var retFuture = newFuture[void]("")
retFuture.complete()
return retFuture
proc p(self: int) {.async.} =
await self.m()
try:
defer: waitFor p(0) # teardown
waitFor((proc() {.async.} = discard await t())()) # asyncTest
except CatchableError:
discard
is working cc @arnetheduck
simplified:
import chronos # only depends on asyncloop's transitive closure
proc t(): Future[void] =
var retFuture = newFuture[void]("")
retFuture.fail(newException(ValueError, ""))
return retFuture
proc m(transp: int): Future[void] =
var retFuture = newFuture[void]("")
retFuture.complete()
return retFuture
proc p(self: int) {.async.} = await self.m()
try:
try:
waitFor(t()) # asyncTest
finally:
waitFor p(0) # teardown
except CatchableError:
discard
Upstream bug: https://github.com/nim-lang/Nim/issues/23390
Across all of Nim 1.6 refc and Nim 2.0 and devel refc and ORC:
Nim versions:
And this does trigger with the Chronos commit in
nimbus-eth2
, as well as the one one gets from cloning this repo in a default way.