-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nim crashes randomly #16613
Comments
@yglukhov can you:
to help narrow down, several flags can help:
EDIT: it's not impossible this is related to #17527, and that it'd be caused by a GC issue, can you read this comment #17527 (comment) and try with |
@timotheecour were you unable to reproduce the crash? |
that's odd, it should; did you re-build nim with those flags (which is what's needed) or compile your program with those flags? next step would be to minimize to remove any module dependency, since it's a compiler bug |
Does it mean that you tried to reproduce it and failed? |
with which does show the stacktrace messages (it crashed after running for 2 minutes)
it means it's hard to investigate without the bug minimized |
TLDR: see workaround below, this would be fixed by nim-lang/RFCs#276
if regs[ra].nodeAddr == nil:
stackTrace(c, tos, pc, "D20210729T134630")
let n2 = regs[ra].nodeAddr[]
if n2 == nil:
stackTrace(c, tos, pc, "D20210729T134630.2")
if n == nil:
stackTrace(c, tos, pc, "D20210729T134630.3")
if (nfIsRef notin regs[ra].nodeAddr[].flags and
nfIsRef notin n.flags):
regs[ra].nodeAddr[][] = n[]
import iface, unittest
# import std/vmutils
iface Animal:
proc say(): string
proc test2()
type
Dog = ref object of RootRef
testCalled: bool
proc say(d: Dog): string = "bark"
proc test2(d: Dog) =
d.testCalled = true
proc doSmth(a: Animal): string =
a.test2()
result = a.say()
proc createVoldemortObject(): Animal =
type Hidden = ref object of RootRef
proc test2(h: Hidden) = discard
suite "iface":
test "runtime":
let d = Dog.new()
doAssert doSmth(d) == "bark"
doAssert d.testCalled
block:
# static: vmTrace(true)
when defined case1:
const s = static:
let d = Dog.new()
let res = doSmth(d)
doAssert(d.testCalled)
0
when defined case2:
const s = (proc(): auto =
let d = Dog.new()
let res = doSmth(d)
doAssert(d.testCalled)
0)() => crashes with -d:case1
# const s = static:
const s = (proc(): auto =
let d = Dog.new()
let res = doSmth(d)
doAssert(d.testCalled)
0)() => no crash regardless of nim-lang/RFCs#276, this should be further investigated, ideally by finding a reduced example that exhibits the bug all the time instead of just once every 2 minutes |
The crash happens, because PNode gets collected as no refs point to it. It is accessed though Line 680 in bbe05c1
|
possibly, but can you show a reduced test case (with no imports) to demonstrate this? Once we have a reduced test case, we can think about ways to fix this, possibly by adding gc'd references to all PNode's for which we've taken the address, storing in some |
I don't have any, and I'm not sure it'll help, judging from the randomness of this issue. However, I've added some code to nim that proves my point and shows 100% reproducibility. |
that's great to have a way to reproduce at 100%, I can indeed reproduce via #18628 However, we still need a minimized test case (now that we have a way to reproduce at 100% via that PR), to make it easier to understand the issue and fix it (even if it's indeed due to gc collecting nodeAddr) A potential fix is by maintaining a |
I've been thinking of a similar approach, but not to use a |
Ideally though it would be great to get rid of unsafe code ( |
#19515 looks a lot like it could fix this issue, doesn't it? |
…im-lang#16780 nim-lang#16613 nim-lang#14553 nim-lang#19909 nim-lang#18641 (nim-lang#19902) [backport] * revert nim-lang#12217 since the root problem seems to have been fixed; fix nim-lang#15974;fix nim-lang#12551; fix nim-lang#19464 * fix nim-lang#16020; fix nim-lang#16780 * fix tests and nim-lang#16613 * fix nim-lang#14553 * fix nim-lang#19909; skip skipRegisterAddr * fix nim-lang#18641
Steps to reproduce:
Wait for 5 minutes
Actual result:
Nim eventually crashes with stack trace:
Nim version: bbe05c1
The text was updated successfully, but these errors were encountered: