Skip to content
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

Boehm GC does not scan thread-local storage #14364

Closed
stefantalpalaru opened this issue May 16, 2020 · 0 comments
Closed

Boehm GC does not scan thread-local storage #14364

stefantalpalaru opened this issue May 16, 2020 · 0 comments

Comments

@stefantalpalaru
Copy link
Contributor

That's how you get surprise deallocations for targets of pointers that are only in threadvars.

https://www.hboehm.info/gc/gcinterface.html :

"Thread users should also be aware that on many platforms objects reachable only from thread-local variables may be prematurely reclaimed. Thus objects pointed to by thread-local variables should also be pointed to by a globally visible data structure."

gc-8.0.4/README.QUICK :

"The collector does not guarantee to scan thread-local storage (e.g. of the kind accessed with pthread_getspecific()). The collector does scan thread stacks though, so generally the best solution is to ensure that any pointers stored in thread-local storage are also stored on the thread's stack for the duration of their lifetime."


I found that out the hard way (Valgrind output):

==20803== Jump to the invalid address stated on the next line
==20803==    at 0x10: ???
==20803==    by 0x2C38DF: zonedTimeFromTime__zT9bMgAwfe1o0G71u2tO24Q (times.nim:1064)
==20803==    by 0x2C38DF: inZone__o59cT0ssqq4BC09cuUGSdJiA (times.nim:1093)
==20803==    by 0x2C38DF: local__JDUz4bfwLSZvJxYV9aiNG9bg (times.nim:1235)
==20803==    by 0x2C38DF: now__YmAcAi9bz5G8OQqVFWHN2uA (times.nim:1263)
==20803==    by 0x38F0FE: rfcTimestamp__i2AqQvvKFsZl0RRd5ysaHA (log_output.nim:426)
==20803==    by 0x38F0FE: initLogRecord__AdFvJuSUXMySj9bot5WYdCQ (log_output.nim:438)
==20803==    by 0x58C8DF: generateDeposits__u9cJTyqoU2khEGAmzCsRniA (chronicles.nim:305)
==20803==    by 0x5AB7D3: main__kYRn29bPOsjfiAecYiv9b2ng (beacon_node.nim:1007)
==20803==    by 0x5B56C1: NimMain (mainchain_monitor.nim:490)
==20803==    by 0x12AD8C: main (mainchain_monitor.nim:497)
==20803==  Address 0x10 is not stack'd, malloc'd or (recently) free'd
==20803== 

lib/pure/times.nim:

var localInstance {.threadvar.}: Timezone

And Timezone is a ref object:

  Timezone* = ref object ## \
      ## Timezone interface for supporting `DateTime <#DateTime>`_\s of arbitrary
      ## timezones. The ``times`` module only supplies implementations for the
      ## systems local time and UTC.
    zonedTimeFromTimeImpl: proc (x: Time): ZonedTime
        {.tags: [], raises: [], benign.}
    zonedTimeFromAdjTimeImpl: proc (x: Time): ZonedTime
        {.tags: [], raises: [], benign.}
    name: string
stefantalpalaru added a commit to stefantalpalaru/Nim that referenced this issue May 16, 2020
Turn on the TLS emulation when using Boehm, since it doesn't scan the
real TLS.
@Araq Araq closed this as completed in 27741d6 May 18, 2020
narimiran pushed a commit that referenced this issue May 19, 2020
Turn on the TLS emulation when using Boehm, since it doesn't scan the
real TLS.

(cherry picked from commit 27741d6)
EchoPouet pushed a commit to EchoPouet/Nim that referenced this issue Jun 13, 2020
Turn on the TLS emulation when using Boehm, since it doesn't scan the
real TLS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant