From 87f6a9592cbbace5e8f0d647841b4490bb7c0f1f Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 8 Jul 2020 08:21:55 +0200 Subject: [PATCH] fixes #14402 (#14908) * fixes #14402 * added a test case --- lib/pure/asyncstreams.nim | 2 +- tests/arc/tasyncorc.nim | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/arc/tasyncorc.nim diff --git a/lib/pure/asyncstreams.nim b/lib/pure/asyncstreams.nim index 44e73003ee..393262c4f6 100644 --- a/lib/pure/asyncstreams.nim +++ b/lib/pure/asyncstreams.nim @@ -96,7 +96,7 @@ proc read*[T](future: FutureStream[T]): owned(Future[(bool, T)]) = if resFut.finished: return # We don't want this callback called again. - future.cb = nil + #future.cb = nil # The return value depends on whether the FutureStream has finished. var res: (bool, T) diff --git a/tests/arc/tasyncorc.nim b/tests/arc/tasyncorc.nim new file mode 100644 index 0000000000..56b8909b1f --- /dev/null +++ b/tests/arc/tasyncorc.nim @@ -0,0 +1,26 @@ +discard """ + output: '''230000''' + cmd: '''nim c --gc:orc -d:useMalloc $file''' + valgrind: "true" +""" + +# bug #14402 + +import asynchttpserver, asyncdispatch, httpclient, strutils + +proc cb(req: Request) {.async, gcsafe.} = + const html = " ".repeat(230000) + await req.respond(Http200, html) + +var server = newAsyncHttpServer() +asyncCheck server.serve(Port(8080), cb) + +proc test {.async.} = + var + client = newAsyncHttpClient() + resp = await client.get("http://localhost:8080") + + let x = (await resp.body).len + echo x # crash + +waitFor test()