This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Invalid check on the result of pthread_self() leads to libpython startup failure
Type: crash Stage:
Components: Interpreter Core Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: tgl
Priority: normal Keywords:

Created on 2019-10-30 17:29 by tgl, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg355723 - (view) Author: Tom Lane (tgl) Date: 2019-10-30 17:29
Assorted code in the Python core supposes that the result of pthread_self() cannot be equal to PYTHREAD_INVALID_THREAD_ID, ie (void *) -1.  If it is, you get a crash at interpreter startup.  Unfortunately, this supposition is directly contrary to the POSIX specification for pthread_self(), which defines no failure return value; and it is violated by NetBSD's implementation in some circumstances.  In particular, we (the Postgres project) are observing that libpython.so fails when dynamically loaded into a host executable that does not itself link libpthread.  NetBSD's code always returns -1 if libpthread was not present at main program start, as they do not support forking new threads in that case.  They assert (and I can't disagree) that their implementation conforms to POSIX.

A lazy man's solution might be to change PYTHREAD_INVALID_THREAD_ID to some other value like -3, but that's not fixing the core problem that you're violating POSIX by testing for any specific value at all.

Details and background info can be found in this email thread:

1560896200%40sss.pgh.pa.us">https://www.postgresql.org/message-id/flat/25662.1560896200%40sss.pgh.pa.us
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82827
2019-10-30 17:29:23tglcreate