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: Automatic Unload of Dynamic Library Cause Segfault
Type: crash Stage: resolved
Components: ctypes Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Chinh Nguyen, iritkatriel
Priority: normal Keywords:

Created on 2017-04-17 14:18 by Chinh Nguyen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg291798 - (view) Author: Chinh Nguyen (Chinh Nguyen) Date: 2017-04-17 14:18
I'm using ctypes to access the PAM library to change a user's password. That is, using the function pam_chauthtok. This is occurring inside a python celery worker in FreeBSD. This will work the first time, the second time generates a segfault and crashes the worker.

On attaching gdb to the worker process, I observe the following:
* Crash occurs in function login_setcryptfmt
* Setting a breakpoint there, I see the following after the first successful password change "warning: Temporarily disabling breakpoints for unloaded shared library "/lib/libcrypt.so.5"
* When there is segfault on the second password change, the location of the segfault cannot be disassemble
* It doesn't look like libcrypt is a direct dependency of libpam.

So it looks like what is happening is this:
* libcrypt is loaded (by python/system?) to invoke some password-related functions, it is then unloaded (by python/system?)
* When the same function is invoked again, somehow libcrypt does not get loaded. This results in a function call to the same function address which is now invalid.

My current work-around is to include libcrypto explicitly by binding to it though I don't use it directly. For example, libcrypt = CDLL(find_library("crypt")).

Other notes:
* This does not occur if I launch celery worker all running in the same process via the celery "green threads" module eventlet
* This only happens if the celery worker is a python child process. I don't know how celery spawns child processes.
msg401315 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-07 17:39
Python 2.7 is no longer being maintained. If you are still seeing this problem on a current version (>= 3.9), please create a new issue.

Ideally, please provide instructions how to reproduce the bug.  It is hard to debug just from a description (particularly when it involves third party components).
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74275
2021-09-07 17:39:52iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg401315

resolution: out of date
stage: resolved
2017-04-17 14:18:15Chinh Nguyencreate