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

WeeChat crashes on exit when both title.py and autosort.py are loaded with Python 3.12 (voidlinux) #2046

Closed
laemeiqu opened this issue Nov 21, 2023 · 13 comments · Fixed by #2126
Assignees
Labels
bug Unexpected problem or unintended behavior
Milestone

Comments

@laemeiqu
Copy link

Bug summary

When using weechat-4.1.1_1 and weechat-python-4.1.1_1 under voidlinux. When scripts title.py and autosort.py are both installed weechat crashes on exit.

Steps to reproduce

1. /script load title.py
2. /script load autosort.py
3. /exit

If no crash at this time then reloading weechat and /exit will definitely crash weechat in voidlinux.

Current behavior

Weechat crashes during exit when both scripts are installed.

Expected behavior

Weechat doesn't crash on exit when both scripts are installed.

Suggested solutions

Additional information

After bulding debug packages in voidlinux

gdb /usr/bin/weechat

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff626f76d in PyObject_GC_UnTrack () from /usr/lib/libpython3.12.so.1.0

bt full

#0  0x00007ffff626f76d in PyObject_GC_UnTrack () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#1  0x00007ffff62a2099 in ?? () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#2  0x00007ffff62251e5 in ?? () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#3  0x00007ffff6220276 in ?? () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#4  0x00007ffff6225bd5 in _PyModule_ClearDict () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#5  0x00007ffff62eaaf6 in ?? () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#6  0x00007ffff62ead6b in Py_EndInterpreter () from /usr/lib/libpython3.12.so.1.0
No symbol table info available.
#7  0x00007ffff66ea2a0 in weechat_python_unload (script=0x555555df3550)
    at /builddir/weechat-4.1.1/src/plugins/python/weechat-python.c:975
        rc = <optimized out>
        interpreter = 0x7ffff5bec910
        filename = 0x555555e69230 "/home/roald/.local/share/weechat/python/autoload/title.py"
#8  0x00007ffff66ea375 in weechat_python_unload_all ()
    at /builddir/weechat-4.1.1/src/plugins/python/weechat-python.c:1024
No locals.
#9  0x00007ffff670a12c in plugin_script_end (weechat_plugin=weechat_plugin@entry=0x555555b5cd10, 
    plugin_data=plugin_data@entry=0x7ffff671bd00 <python_data>)
    at /builddir/weechat-4.1.1/src/plugins/plugin-script.c:1789
        scripts_loaded = 1
#10 0x00007ffff66eb681 in weechat_plugin_end (plugin=0x555555b5cd10)
    at /builddir/weechat-4.1.1/src/plugins/python/weechat-python.c:1563
No locals.
#11 0x00005555555fadb6 in plugin_unload (plugin=0x555555b5cd10)
    at /builddir/weechat-4.1.1/src/plugins/plugin.c:1253
        end_func = <optimized out>
        name = 0x555555fcd320 "python"
#12 0x00005555555fae69 in plugin_unload_all () at /builddir/weechat-4.1.1/src/plugins/plugin.c:1305
        plugins_loaded = <optimized out>
#13 0x00005555555fb122 in plugin_end () at /builddir/weechat-4.1.1/src/plugins/plugin.c:1425
No locals.
#14 0x00005555555630c2 in weechat_end (gui_end_cb=0x5555555f43d0 <gui_main_end>)
    at /builddir/weechat-4.1.1/src/core/weechat.c:708
No locals.
#15 0x00005555555620d6 in main (argc=1, argv=0x7fffffffe118)
    at /builddir/weechat-4.1.1/src/gui/curses/normal/main.c:45
No locals.

  • WeeChat version:  weechat-4.1.1_1
  • OS, distribution and version:  Voidlinux (fully updated on Tue Nov 21 2023)
  • Terminal: foot
  • Terminal multiplexer (screen/tmux/…/none): none
@laemeiqu
Copy link
Author

If title is unloaded before autosort then weechat does not crash on exit:

  1. /script unload title
  2. /exit
  3. no crash

If autosort is unloaded before title then weechat does crash on exit or on unloading of title:

  1. /script unload autosort
  2. /script unload title
  3. crash

@flashcode
Copy link
Member

Does the crash happen with any Python script?
Did you try with two different scripts (if possible very small scripts, doing almost nothing)?

@laemeiqu
Copy link
Author

I can reproduce this crash with other python plugins. I reproduced the crash with the scripts go.py and grep.py both installed.

If grep.py is unloaded before go.py then weechat does not crash on exit:

  1. /script unload grep.py
  2. /exit
  3. no crash

If go.py is unloaded before grep.py then weechat does crash on exit or on unloading of grep.py:

  1. /script unload go.py
  2. /script unload grep.py
  3. crash

Note: going straight for /exit when grep.py and go.py are both installed and loaded also results in the crash.

@flashcode
Copy link
Member

Hi,
I can not reproduce on Debian (Sid/unstable) with Python 3.11 (not 3.12, that could explain), is it possible to write a short Dockerfile based on voidlinux to reproduce the crash inside, so I can investigate?

@flashcode flashcode added the waiting info Waiting for info from author of issue label Nov 30, 2023
@flashcode flashcode self-assigned this Nov 30, 2023
@rjarry
Copy link
Contributor

rjarry commented Feb 20, 2024

Hi there,

I can also reproduce the issue with read_marker.py and soju.py loaded, in that order. For some reason, loading soju.py first does not trigger the issue every time.

Reproducer:

  • run weechat -s to disable autoloading of any script
  • /script load read_marker.py
  • /script load soju.py
  • /quit

Here is some more debug info if that helps:

Python 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] on linux

======= WeeChat backtrace =======
(written by WeeChat 4.2.1, compiled on Feb 14 2024 23:44:18)
001  /home/rjarry/upstream/weechat/src/core/wee-backtrace.c:167 [function weechat_backtrace]
002  /home/rjarry/upstream/weechat/src/core/wee-debug.c:192 [function debug_sigsegv_cb]
003  ??:? [function __restore_rt]
004  ??:? [function _PyObject_FastCallDictTstate]
005  ??:? [function PyObject_Free]
006  ??:? [function _PyModule_ClearDict]
007  ??:? [function PyGC_Collect]
008  ??:? [function Py_EndInterpreter]
009  /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:978 [function weechat_python_unload]
010  /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:1022 [function weechat_python_unload_all]
011  /home/rjarry/upstream/weechat/src/plugins/plugin-script.c:1791 [function plugin_script_end]
012  /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:1569 [function weechat_plugin_end]
013  /home/rjarry/upstream/weechat/src/plugins/plugin.c:1259 [function plugin_unload]
014  /home/rjarry/upstream/weechat/src/plugins/plugin.c:1306 [function plugin_unload_all]
015  /home/rjarry/upstream/weechat/src/plugins/plugin.c:1431 [function plugin_end]
016  /home/rjarry/upstream/weechat/src/core/weechat.c:710 [function weechat_end]
017  /home/rjarry/upstream/weechat/src/gui/curses/normal/main.c:47 [function main]
018  ??:? [function __libc_start_call_main]
019  :? [function __libc_start_main_alias_2]
020  ??:? [function _start]
======= End of  backtrace =======

(gdb) thread apply all bt full

Thread 1 (Thread 0x7f4e332f0a80 (LWP 171986)):
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
        tid = <optimized out>
        ret = 0
        pd = <optimized out>
        old_mask = {
          __val = {[0] = 140730321364448}
        }
        ret = <optimized out>
#1  0x00007f4e33aca8a3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
No locals.
#2  0x00007f4e33a788ee in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
        ret = <optimized out>
#3  0x00007f4e33a608ff in __GI_abort () at abort.c:79
        save_stage = 1
        act = {
          __sigaction_handler = {
            sa_handler = 0x20,
            sa_sigaction = 0x20
          },
          sa_mask = {
            __val = {[0] = 139973852474048, [1] = 416, [2] = 14057664, [3] = 140730321364592, [4] = 139973851178954, [5] = 2, [6] = 18446744073709551472, [7] = 2, [8] = 14057248, [9] = 139973824960864, [10] = 18446744073709551472, [11] = 2, [12] = 12498224, [13] = 140730321364672, [14] = 139973851190238, [15] = 140730321364656}
          },
          sa_flags = 870771879,
          sa_restorer = 0x7f4e318eb790
        }
#4  0x0000000000406e6f in weechat_shutdown (return_code=1, crash=1) at /home/rjarry/upstream/weechat/src/core/weechat.c:600
No locals.
#5  0x00000000004355f7 in debug_sigsegv_cb () at /home/rjarry/upstream/weechat/src/core/wee-debug.c:192
No locals.
#6  <signal handler called>
No locals.
#7  0x00007f4e31df9a8d in _PyGCHead_SET_NEXT (next=0x7f4e318eb730, gc=0x7f4e3225f0c8) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Include/internal/pycore_gc.h:63
No locals.
#8  _PyObject_GC_UNTRACK (op=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Include/internal/pycore_object.h:246
        gc = 0x7f4e318eb780
        prev = 0x7f4e3225f0c8
        next = 0x7f4e318eb730
        gc = <optimized out>
        prev = <optimized out>
        next = <optimized out>
#9  PyObject_GC_UnTrack (op_raw=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Modules/gcmodule.c:2242
        op = 0x7f4e318eb790
        op = <optimized out>
#10 meth_dealloc (m=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Objects/methodobject.c:162
No locals.
#11 0x00007f4e31dec157 in _Py_Dealloc (op=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Objects/object.c:2625
        type = <optimized out>
        dealloc = <optimized out>
#12 Py_DECREF (op=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Include/object.h:706
No locals.
#13 Py_XDECREF (op=0x7f4e318eb790) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Include/object.h:799
No locals.
#14 insertdict (interp=<optimized out>, mp=0x7f4e30bc7b00, key=0x7f4e32172740 <const_str_register>, hash=<optimized out>, value=0x7f4e321d5960 <_Py_NoneStruct>) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Objects/dictobject.c:1319
        old_value = 0x7f4e318eb790
        ix = <optimized out>
#15 0x00007f4e31e4fe60 in PyDict_SetItem (value=0x7f4e321d5960 <_Py_NoneStruct>, key=0x7f4e32172740 <const_str_register>, op=0x7f4e30bc7b00) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Objects/dictobject.c:1883
No locals.
#16 _PyModule_ClearDict (d=0x7f4e30bc7b00) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Objects/moduleobject.c:656
        pos = 6
        key = 0x7f4e32172740 <const_str_register>
        value = 0x7f4e318eb790
        verbose = <optimized out>
#17 0x00007f4e31ebde94 in finalize_modules_clear_weaklist (verbose=0, weaklist=0x7f4e30d294c0, interp=0x230a8e0) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Python/pylifecycle.c:1526
        tup = <optimized out>
        name = 0x7f4e30bc94a0
        mod = 0x7f4e30bd8540
        dict = <optimized out>
        i = 70
#18 finalize_modules (tstate=tstate@entry=0x2368200) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Python/pylifecycle.c:1609
        interp = <optimized out>
        modules = <optimized out>
        verbose = 0
        weaklist = 0x7f4e30d294c0
#19 0x00007f4e31ecb494 in Py_EndInterpreter (tstate=0x2368200) at /usr/src/debug/python3.12-3.12.1-2.fc39.x86_64/Python/pylifecycle.c:2199
        interp = 0x230a8e0
        __func__ = "Py_EndInterpreter"
#20 0x00007f4e323fc007 in weechat_python_unload (script=0x2218e10) at /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:975
        rc = 0x270e6d0
        interpreter = 0x2368200
        filename = 0x5d074a0 "/home/rjarry/.local/share/weechat/python/autoload/soju.py"
#21 0x00007f4e323fc1c7 in weechat_python_unload_all () at /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:1024
No locals.
#22 0x00007f4e3242c8a6 in plugin_script_end (weechat_plugin=0xe592a0, plugin_data=0x7f4e3243a140 <python_data>) at /home/rjarry/upstream/weechat/src/plugins/plugin-script.c:1790
        scripts_loaded = 1
#23 0x00007f4e323fd76d in weechat_plugin_end (plugin=0xe592a0) at /home/rjarry/upstream/weechat/src/plugins/python/weechat-python.c:1568
No locals.
#24 0x00000000004c3fb5 in plugin_unload (plugin=0xe592a0) at /home/rjarry/upstream/weechat/src/plugins/plugin.c:1256
        end_func = 0x7f4e323fd70c <weechat_plugin_end>
        name = 0x1b45be0 "python"
#25 0x00000000004c411c in plugin_unload_all () at /home/rjarry/upstream/weechat/src/plugins/plugin.c:1308
        plugins_loaded = 1
#26 0x00000000004c4475 in plugin_end () at /home/rjarry/upstream/weechat/src/plugins/plugin.c:1428
No locals.
#27 0x00000000004071a9 in weechat_end (gui_end_cb=0x4bb8df <gui_main_end>) at /home/rjarry/upstream/weechat/src/core/weechat.c:709
No locals.
#28 0x0000000000406129 in main (argc=1, argv=0x7ffe54d071d8) at /home/rjarry/upstream/weechat/src/gui/curses/normal/main.c:45
No locals.

@trygveaa
Copy link
Member

I bisected this issue to this commit in cpython: python/cpython@de64e75

@trygveaa
Copy link
Member

trygveaa commented Mar 8, 2024

I posted an issue to CPython for this: python/cpython#116510

I also noticed that it's fixed in version v3.13.0a4.

trygveaa added a commit to trygveaa/weechat that referenced this issue Jun 3, 2024
Python 3.12 has a bug where it crashes when you unload all the
interpreters unless you make sure to unload the first interpreter you
loaded last. For some reason, loading the eval interpreter before any
scripts also seems to prevent the issue, even if the eval interpreter is
unloaded before the other interpreters.

So this just evals an empty string at the end of initing the Python
plugin if the Python version is 3.12, to make sure the eval interpreter
is loaded first.

Fixes weechat#2046
@belkka
Copy link

belkka commented Jun 17, 2024

Guys in IRC helped me to compile weechat's python plugin linked to python3.13. I have:

  • weechat from Archlinux repository (with python plugin linked to python3.12)
  • python313 from AUR (in parallel with python 3.12 from the core repo)
  • weechat python plugin (python.so) linked to python3.13 living in my ~/.local/share/weechat/plugins/, which overrides system-wide plugin.

Here is a guide: https://gist.github.com/belkka/4dc42664fe383983c5a5d9d99da00952

Thanks to trygveaa and others at libera.chat for babysitting me. (do not confuse with trygveaa at github — they could be an impostor)

@flashcode
Copy link
Member

@belkka: FYI, @trygveaa is not an imposter.

flashcode pushed a commit that referenced this issue Jun 23, 2024
Python 3.12 has a bug where it crashes when you unload all the
interpreters unless you make sure to unload the first interpreter you
loaded last. For some reason, loading the eval interpreter before any
scripts also seems to prevent the issue, even if the eval interpreter is
unloaded before the other interpreters.

So this just evals an empty string at the end of initing the Python
plugin if the Python version is 3.12, to make sure the eval interpreter
is loaded first.

Fixes #2046
@flashcode flashcode removed the waiting info Waiting for info from author of issue label Jun 23, 2024
flashcode pushed a commit that referenced this issue Jun 23, 2024
Python 3.12 has a bug where it crashes when you unload all the
interpreters unless you make sure to unload the first interpreter you
loaded last. For some reason, loading the eval interpreter before any
scripts also seems to prevent the issue, even if the eval interpreter is
unloaded before the other interpreters.

So this just evals an empty string at the end of initing the Python
plugin if the Python version is 3.12, to make sure the eval interpreter
is loaded first.

Fixes #2046
flashcode added a commit that referenced this issue Jun 26, 2024
…2046, issue #2126)

This should definitely fix the crash with Python 3.12, even when scripts are
auto-loaded (the previous fix was working only when the scripts are loaded
manually).
flashcode added a commit that referenced this issue Jun 26, 2024
…2046, issue #2126)

This should definitely fix the crash with Python 3.12, even when scripts are
auto-loaded (the previous fix was working only when the scripts are loaded
manually).
@belkka
Copy link

belkka commented Jun 26, 2024

So the issue is fixed even in python 3.12 now? 😮

@flashcode

  1. are you impostor's buddy?
  2. how do you usually verify that some github account and some libera.chat account are controlled by the same person? :)

@flashcode
Copy link
Member

I improved the workaround developed by @trygveaa, so now it should not crash even with auto-loaded scripts.

@belkka: there are no imposters here, if you don't trust us, please stop commenting.

@belkka
Copy link

belkka commented Jun 27, 2024

I confirm that weechat doesn't crash on exit anymore! Thanks! For that I've upgraded to weechat 4.3.3, removed ~/.local/share/weechat/plugins.so, uninstalled python3.13, checked that I do have multiple python scripts installed

@flashcode

(1) no, and this is actually rude. (2) the first question was a joke (which you decided to respond to), but the second question was an initiation of inter-person trust-establishment protocol. (3) I was not asking for this and have nothing to do with this information (even if I could verify the claim). I just pointed out that same-name identities on different hosts can be controlled by different people. I have no idea why you felt like it's important to start and continue this conversation. Feel free to stop as soon as you feel there is nothing valuable to tell; I'm not spamming with follow-ups demanding to answer my questions.

Please, don't teach people to trust verifiable claims WITHOUT verification. Children could read github.

Also, to clarify my wording: I chose the word "impostor" to add a humorous connotation influenced by a community of one popular game. While doing so, I was still only referring to the original meaning of the word (impersonation), not to any of the in-game activities (sabotage/killing). In particular, I didn't mean to say that any of github users could be "saboteurs". I thought I've made it clear from the context by saying "...do not confuse A with B..."

@nascheme
Copy link

@flashcode

I spent some time investigating today and came up with a different work-around. See: python/cpython#116510 (comment)

How does your workaround work, do you think?

@flashcode flashcode changed the title weechat crashes on exit when both title.py and autosort.py are loaded (voidlinux) WeeChat crashes on exit when both title.py and autosort.py are loaded with Python 3.12 (voidlinux) Jul 3, 2024
@flashcode flashcode added this to the 4.4.0 milestone Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants