Skip to content

Referencing to thread argument in a closure causes SIGSEGV (Illegal storage access) #25253

@aj3423

Description

@aj3423

Nim Version

Nim Compiler Version 2.3.1 [Linux: amd64]
Compiled at 2025-09-19
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 3f48576
active boot switches: -d:release

Description

The following code crashes:

type 
  Boss = ref object of RootObj
    name: string

proc crash(boss: Boss) =
  (proc () =
    let a = boss.name # using `boss.name` in this closure causes the crash
  )()

proc working(boss: Boss) =
  boss.crash()

let boss = Boss()

var t: Thread[Boss]
createThread(t, working, boss)
joinThread(t)

Passing by pointer also crashes.

Current Output

Traceback (most recent call last)
/run/media/root/e/nim/3/src/test.nim(5) test
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(527) nimDecRefIsLastCyclicDyn
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(509) rememberCycle
/root/.local/share/grabnim/nim-devel/lib/system/orc.nim(156) unregisterCycle
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

no crash

Known Workarounds

none

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions