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

app_python3: make it compatible with TLS refactoring #3832

Closed
space88man opened this issue Apr 29, 2024 · 2 comments
Closed

app_python3: make it compatible with TLS refactoring #3832

space88man opened this issue Apr 29, 2024 · 2 comments
Assignees

Comments

@space88man
Copy link
Contributor

space88man commented Apr 29, 2024

Description

app_python3 loads libssl and also calls pthread_setspecific(). This makes it incompatible with tls_thread_mode refactoring.

Reported by user @igorolhovskiy on the mailing list:

https://lists.kamailio.org/mailman3/hyperkitty/list/sr-users@lists.kamailio.org/thread/LEN4MVSHXMMUXCE6YJIEFKDPXI5FBOFA/

Troubleshooting

Reproduction

Debugging Data

Log Messages

SIP Traffic

Possible Solutions

  • make it compatible with tls_threads_mode = 1

Additional Information

Backtrace for pyhthon:

Thread 1 "kamailio" hit Breakpoint 2, ___pthread_setspecific (key=6, value=0xb806f0) at pthread_setspecific.c:26        
26      {                                                                                                               
#0  ___pthread_setspecific (key=6, value=0xb806f0) at pthread_setspecific.c:26                                          
#1  0x00007fff769833ed in PyThread_tss_set () from /lib64/libpython3.9.so.1.0                                           
#2  0x00007fff769832b9 in _PyGILState_NoteThreadState () from /lib64/libpython3.9.so.1.0                                
#3  0x00007fff76983360 in init_interp_create_gil () from /lib64/libpython3.9.so.1.0                                     
#4  0x00007fff7697e249 in pyinit_core.constprop () from /lib64/libpython3.9.so.1.0                                      
#5  0x00007fff7697e01d in Py_InitializeFromConfig () from /lib64/libpython3.9.so.1.0                                    
#6  0x00007fff768f4628 in Py_InitializeEx () from /lib64/libpython3.9.so.1.0
#7  0x00007fff76b73403 in apy_load_script () at app_python3_mod.c:379
#8  0x00007fff76b71bea in mod_init () at app_python3_mod.c:169
@space88man space88man self-assigned this Apr 29, 2024
@space88man space88man changed the title app_python3: make compatible with TLS refactoring app_python3: make it compatible with TLS refactoring Apr 29, 2024
space88man added a commit to space88man/kamailio that referenced this issue Apr 29, 2024
- python uses pthread_setspecific and requires to be initialized
  in thread 0
- add a state variable to demarcate libssl thread-local
  keys and Python's thread-local key

Addresses GH kamailio#3832
space88man added a commit to space88man/kamailio that referenced this issue Apr 29, 2024
- python uses pthread_setspecific and requires to be initialized
  in thread 0
- add a state variable to demarcate libssl thread-local
  keys and Python's thread-local key

Addresses GH kamailio#3832
@space88man
Copy link
Contributor Author

@igorolhovskiy - are you able to test this branch from master(5.9-dev): https://github.com/kamailio/kamailio/tree/fix-tls-python

It has a few commits to make tls_threads_mode=1|2 compatible with app_python3.

space88man added a commit to space88man/kamailio that referenced this issue Apr 29, 2024
- python uses pthread_setspecific and requires to be initialized
  in thread 0
- add a state variable to demarcate libssl thread-local
  keys and Python's thread-local key

Addresses GH kamailio#3832
@igorolhovskiy
Copy link
Contributor

@space88man
I can confirm, that fix is working for 5.8 branch with commit cafe437

No deadlock with tls_threads_mode=2 and also no fail under TLS load for both modes.

Many thanks!

(As I was testing soon after you backported commit to 5.8, I really scratched my head why I cannot replicate the issue)

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

2 participants