微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

动态导入加载 libssl 的模块时锁定

如何解决动态导入加载 libssl 的模块时锁定

在尝试导入依赖于 PyJWT 的模块时,我遇到了一个奇怪的问题(因此,我相信在某些时候会依赖于 libssl)。

在多进程应用程序中,一些“工人”执行以下操作:

module = importlib.import_module(module_name)

其中 module_name 在某个时刻导入 PYJWT 模块。

在极少数情况下,导入会无限期挂起。 gdbing 有罪进程显示以下堆栈:

#0  0x00007f16f47bdb3b in do_futex_wait.constprop.1 () from /usr/lib64/libpthread.so.0
#1  0x00007f16f47bdbcf in __new_sem_wait_slow.constprop.0 () from /usr/lib64/libpthread.so.0
#2  0x00007f16f47bdc6b in sem_wait@@GLIBC_2.2.5 () from /usr/lib64/libpthread.so.0
#3  0x00007f16f2f35d55 in PyThread_acquire_lock () from /usr/lib64/libpython2.7.so.1.0
#4  0x00007f16f37cb037 in CRYPTO_add_lock () from /usr/lib64/libcrypto.so.10
#5  0x00007f16f38c6245 in X509_STORE_free () from /usr/lib64/libcrypto.so.10
#6  0x00007f16f3c0382a in SSL_CTX_free () from /usr/lib64/libssl.so.10
#7  0x00007f16eef90f02 in context_dealloc () from /usr/lib64/python2.7/lib-dynload/_ssl.so
#8  0x00007f16f2ec21b3 in subtype_dealloc () from /usr/lib64/libpython2.7.so.1.0
#9  0x00007f16f2ec00d3 in tupledealloc () from /usr/lib64/libpython2.7.so.1.0
#10 0x00007f16f2ec21b3 in subtype_dealloc () from /usr/lib64/libpython2.7.so.1.0
#11 0x00007f16f2e996ba in list_dealloc () from /usr/lib64/libpython2.7.so.1.0
#12 0x00007f16f2e9897b in list_clear () from /usr/lib64/libpython2.7.so.1.0
#13 0x00007f16f2f38f5a in collect () from /usr/lib64/libpython2.7.so.1.0
#14 0x00007f16f2f39887 in _PyObject_GC_Malloc () from /usr/lib64/libpython2.7.so.1.0
#15 0x00007f16f2f398cd in _PyObject_GC_New () from /usr/lib64/libpython2.7.so.1.0
#16 0x00007f16f2ea67f4 in PyDict_New () from /usr/lib64/libpython2.7.so.1.0
#17 0x00007f16f2f29d30 in analyze_block () from /usr/lib64/libpython2.7.so.1.0
#18 0x00007f16f2f29e12 in analyze_block () from /usr/lib64/libpython2.7.so.1.0
#19 0x00007f16f2f2bd84 in PySymtable_Build () from /usr/lib64/libpython2.7.so.1.0
#20 0x00007f16f2f121d2 in PyAST_Compile () from /usr/lib64/libpython2.7.so.1.0
#21 0x00007f16f2f24b79 in run_mod () from /usr/lib64/libpython2.7.so.1.0
...

认为问题是在某些时候导入 PYJWT 调用 libssl.CRYPTO_add_lock 这...死锁。我现在只能猜测。

有什么线索可以解释这种行为吗?

我在 RHEL 7.7 上使用 Python 2.7.5(我知道,我知道...)和 PyJWT 1.7.1 和 cryptography 3.3.2。>

我已经尝试了 in this Github issue 描述的 kludge ,但没​​有运气:

import cryptography.hazmat.backends.openssl.backend
cryptography.hazmat.backends.openssl.backend.activate_builtin_random()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。