Skip to content

segfault in python multithreaded setting #1868

@soumith

Description

@soumith

Zihang Dai reports (and I've reproduced) that the autograd engine is not thread-safe.
Here's a repro script: https://gist.github.com/zihangdai/fc8f76fbb8a0f6323a6b31e6d98ceb50
Run it a few times, occassionally it segfaults.

Segfault is from a much different location, when cleaning up imports:

Thread 1 "python" received signal SIGSEGV, Segmentation fault.
malloc_consolidate (av=av@entry=0x7ffff70a8b20 <main_arena>) at malloc.c:4167
4167    malloc.c: No such file or directory.
(gdb) where
#0  malloc_consolidate (av=av@entry=0x7ffff70a8b20 <main_arena>) at malloc.c:4167
#1  0x00007ffff6d64678 in _int_free (av=0x7ffff70a8b20 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:4075
#2  0x00007ffff6d6853c in __GI___libc_free (mem=<optimized out>) at malloc.c:2968
#3  0x00007ffff7a6a427 in dict_dealloc (mp=0x7ffff7ed0c58) at Objects/dictobject.c:1044
#4  0x00007ffff7a682c7 in insertdict_by_entry (mp=0x7ffff7ed0d70, key='build_time_vars', hash=<optimized out>, ep=<optimized out>, value=<optimized out>) at Objects/dictobject.c:519
#5  0x00007ffff7a6b79c in insertdict (value=None, hash=-295987683324531010, key='build_time_vars', mp=0x7ffff7ed0d70) at Objects/dictobject.c:556
#6  dict_set_item_by_hash_or_entry (value=None, ep=0x0, hash=-295987683324531010, key='build_time_vars',
    op={'__builtins__': {'bytearray': <type at remote 0x7ffff7d7c300>, 'IndexError': <type at remote 0x7ffff7d82bc0>, 'all': <built-in function all>, 'help': <_Helper at remote 0x7ffff7ed8c50>, 'vars': <built-in function vars>, 'SyntaxError': <type at remote 0x7ffff7d82540>, 'unicode': <type at remote 0x7ffff7d99040>, 'UnicodeDecodeError': <type at remote 0x7ffff7d833e0>, 'memoryview': <type at remote 0x7ffff7d8d900>, 'isinstance': <built-in function isinstance>, 'copyright': <_Printer(_Printer__data='Copyright (c) 2001-2016 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.', _Printer__lines=None, _Printer__name='copyright', _Printer__dirs=(), _Printer__files=(...)) at remote 0x7ffff7ed8a10>, 'NameError': <type at remote 0x7ffff7d82060>, 'BytesWarning': <type at remote 0x7ffff...(truncated)) at Objects/dictobject.c:795
#7  PyDict_SetItem (
    op={'__builtins__': {'bytearray': <type at remote 0x7ffff7d7c300>, 'IndexError': <type at remote 0x7ffff7d82bc0>, 'all': <built-in function all>, 'help': <_Helper at remote 0x7ffff7ed8c50>, 'vars': <built-in function vars>, 'SyntaxError': <type at remote 0x7ffff7d82540>, 'unicode': <type at remote 0x7ffff7d99040>, 'UnicodeDecodeError': <type at remote 0x7ffff7d833e0>, 'memoryview': <type at remote 0x7ffff7d8d900>, 'isinstance': <built-in function isinstance>, 'copyright': <_Printer(_Printer__data='Copyright (c) 2001-2016 Python Software Foundation.\nAll Rights Reserved.\n\nCopyright (c) 2000 BeOpen.com.\nAll Rights Reserved.\n\nCopyright (c) 1995-2001 Corporation for National Research Initiatives.\nAll Rights Reserved.\n\nCopyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.\nAll Rights Reserved.', _Printer__lines=None, _Printer__name='copyright', _Printer__dirs=(), _Printer__files=(...)) at remote 0x7ffff7ed8a10>, 'NameError': <type at remote 0x7ffff7d82060>, 'BytesWarning': <type at remote 0x7ffff...(truncated), key='build_time_vars', value=None)
    at Objects/dictobject.c:848
#8  0x00007ffff7a6ea8d in _PyModule_Clear (m=<optimized out>) at Objects/moduleobject.c:139
#9  0x00007ffff7aec4a1 in PyImport_Cleanup () at Python/import.c:512
#10 0x00007ffff7af957b in Py_Finalize () at Python/pythonrun.c:458
#11 0x00007ffff7b0f8e5 in Py_Main (argc=<optimized out>, argv=<optimized out>) at Modules/main.c:670
#12 0x00007ffff6d04830 in __libc_start_main (main=0x4007f0 <main>, argc=2, argv=0x7fffffffe008, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdff8) at ../csu/libc-start.c:291
#13 0x0000000000400729 in _start ()

Metadata

Metadata

Assignees

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