Hi,
I have some code that calls async HTTP client. It works on Nim 1.4.8 but fails on 1.6.10. Seems some memory is freed before the future is completed. Any idea what I did wrong?
The async design in Gene language is I create a pseudo Future that will be completed when the underlying async HTTP request is completed. This mechanism seems working fine in 1.4.x
$ gene examples/http_async.gene Traceback (most recent call last)
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncmacro.nim(31) parseResponseNimAsyncContinue
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/httpclient.nim(868) parseResponseIter
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncmacro.nim(232) parseBody
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncmacro.nim(28) parseBodyNimAsyncContinue
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/httpclient.nim(759) parseBodyIter
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncmacro.nim(232) parseChunks
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncmacro.nim(28) parseChunksNimAsyncContinue
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/httpclient.nim(714) parseChunksIter
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/pure/asyncnet.nim(596) recvLine
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(483) nimDecRefIsLastCyclicDyn
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(472) rememberCycle
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(413) registerCycle
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(383) collectCycles
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(319) collectCyclesBacon
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(188) markGray
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(80) trace
/Users/gcao/.choosenim/toolchains/nim-1.6.10/lib/system/orc.nim(133) nimTraceRefDyn
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
https://github.com/gcao/gene-new/blob/master/examples/http_async.gene#L12-L14
(await
(genex/http/get_async
("" base_url "/news?symbols=AAPL&access_key=" token))))
Run
https://github.com/gcao/gene-new/blob/issue50_thread_support_2/src/gene/features/async.nim#L35-L41
proc await ( self : Value ) : Value =
case self . kind :
of VkFuture :
if self . future . finished :
result = self . future . read ( )
else :
result = wait_for ( self . future )
...
Run
https://github.com/gcao/gene-new/blob/issue50_thread_support_2/src/genex/http.nim#L351-357
var client = newAsyncHttpClient ( )
client . headers = headers
var f = client . get_content ( url )
var future = new_future [ Value ] ( )
f . add_callback proc ( ) { . gcsafe . } =
future . complete ( f . read ( ) )
result = new_gene_future ( future )
Run