Open PhilippMDoerner opened 5 months ago
simplified version:
import chronos
var counter{.threadvar.}: int
const MESSAGE_COUNT = 10
proc process1Message() {.async.} =
await sleepAsync(100)
counter.inc
echo "after ", counter
proc main() =
for i in 0..<MESSAGE_COUNT:
asyncSpawn process1Message()
while counter != MESSAGE_COUNT:
poll()
echo "FINISHED"
when defined(gcOrc):
GC_fullCollect() # from orc.nim. Has no destructor.
main()
Heyho,
While writing code for a library of mine with chronos I noticed that some of my tests were showing leaks under address sanitizer, but only under
--mm:arc
. I managed to reduce it down to a minimal example - The main thread sends 10 messages to a receiver thread, which processes them in an async proc.Given that the leaks only occurs under arc and the number of leaks scales perfectly with the number of messages sent (3 per message) I'm prone to assuming that there's a cycle occuring somewhere, though I can't claim to understand where or how.
Example
When running this with the following command with orc it will not show any leaks:
When running this with the same command but with arc it will show leaks:
This will find around 3 leaks per message
Stacktrace
Nim Version:
Chronos version:
chronos-3.2.0-f5d800dc752d4f55b9059936539489e008f201fa
That should be the last or second-to-last commit on the repo since I installed the chronos version via
requires "chronos#head"
around 5h ago.