Bug 258212 - net-im/telegram-desktop: stop reason = signal SIGSEGV
Summary: net-im/telegram-desktop: stop reason = signal SIGSEGV
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
Depends on: 258360
  Show dependency treegraph
Reported: 2021-09-02 13:33 UTC by Dmitry Wagin
Modified: 2021-09-17 18:25 UTC (History)
4 users (show)

See Also:
henry.hu.sh: maintainer-feedback+


Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Wagin 2021-09-02 13:33:04 UTC
I suppose after upgrade glib 2.68.3,2 -> 2.68.4,2 telegram-desktop stopped working.

(lldb) bt
* thread #1, name = 'gdbus', stop reason = signal SIGSEGV
  * frame #0: 0x000000081000c36e libc.so.7`localeconv_l(loc=0x0000000810121448) at localeconv.c:91:2
    frame #1: 0x0000000810061e67 libc.so.7`__vfprintf(fp=0x00007fffdfbf9ea8, locale=0x0000000810121448, fmt0="", ap=0x00007fffdfbf9fe0) at vfprintf.c:480:18
    frame #2: 0x00000008100606bf libc.so.7`snprintf(str="", n=<unavailable>, fmt="") at snprintf.c:74:8
    frame #3: 0x000000080ffff22d libc.so.7`_citrus_esdb_open(db=0x00007fffdfbfad70, esname="UTF-8") at citrus_esdb.c:201:2
    frame #4: 0x000000080f9fcb77 libiconv_std.so.4`_citrus_iconv_std_iconv_init_shared(ci=0x000000081403c5d0, src="UTF-8", dst="UTF-8") at citrus_iconv_std.c:365:8
    frame #5: 0x000000080fffff01 libc.so.7`_citrus_iconv_open [inlined] open_shared(rci=<unavailable>, convname="UTF-8/UTF-8", src="UTF-8", dst="UTF-8") at citrus_iconv.c:180:8
    frame #6: 0x000000080ffffe63 libc.so.7`_citrus_iconv_open [inlined] get_shared(rci=<unavailable>, src="UTF-8", dst="UTF-8") at citrus_iconv.c:235
    frame #7: 0x000000080ffffdf5 libc.so.7`_citrus_iconv_open(rcv=0x00007fffdfbfba78, src=<unavailable>, dst=<unavailable>) at citrus_iconv.c:313
    frame #8: 0x0000000810003305 libc.so.7`__bsd___iconv_open(out="UTF-8", in="UTF-8", handle=0x0000000000000000) at bsd_iconv.c:79:9
    frame #9: 0x000000080c7bd29f libintl.so.8`_nl_find_msg + 1423
    frame #10: 0x000000080c7bc993 libintl.so.8`libintl_dcigettext + 1523
    frame #11: 0x000000080e60858f libgio-2.0.so.0`g_cancellable_set_error_if_cancelled + 47
    frame #12: 0x000000080e65e7c2 libgio-2.0.so.0`___lldb_unnamed_symbol1359$$libgio-2.0.so.0 + 178
    frame #13: 0x000000080e65c753 libgio-2.0.so.0`g_socket_receive_message + 51
    frame #14: 0x000000080e6db96b libgio-2.0.so.0`___lldb_unnamed_symbol2769$$libgio-2.0.so.0 + 123
    frame #15: 0x000000080e65fed2 libgio-2.0.so.0`___lldb_unnamed_symbol1377$$libgio-2.0.so.0 + 162
    frame #16: 0x000000080e8487ee libglib-2.0.so.0`g_main_context_dispatch + 366
    frame #17: 0x000000080e848b94 libglib-2.0.so.0`___lldb_unnamed_symbol122$$libglib-2.0.so.0 + 548
    frame #18: 0x000000080e848eda libglib-2.0.so.0`g_main_loop_run + 234
    frame #19: 0x000000080e6dae0b libgio-2.0.so.0`___lldb_unnamed_symbol2764$$libgio-2.0.so.0 + 27
    frame #20: 0x000000080e873a12 libglib-2.0.so.0`___lldb_unnamed_symbol231$$libglib-2.0.so.0 + 66
    frame #21: 0x000000080c78f76a libthr.so.3`thread_start(curthread=0x0000000814013c00) at thr_create.c:292:16
Comment 1 Henry Hu 2021-09-08 03:16:51 UTC
Hm, interesting, I've just reinstalled my telegram-desktop locally, and it's crashing. At least it's easily reproducible.
Comment 2 Henry Hu 2021-09-08 03:46:56 UTC
I noticed that this issue is non-deterministic, i.e., if you repeatedly start telegram-desktop, sometimes it starts fine.
Do you observe the same thing?
Comment 3 Henry Hu 2021-09-08 04:04:26 UTC
I'm able to reproduce this with a simple program:

#include <iconv.h>
#include <pthread.h>
#include <locale.h>

void* iconv_thread(void* arg) {
    iconv_open("UTF-8", "UTF-8");
    return NULL;

void* locale_thread(void* arg) {
    setlocale(LC_ALL, "en_US.UTF-8");
    return NULL;

int main() {
    pthread_t t1, t2;
    pthread_create(&t1, NULL, iconv_thread, NULL);
    pthread_create(&t2, NULL, locale_thread, NULL);
    pthread_join(t1, NULL);
    pthread_join(t2, NULL);

Seems to be an issue in concurrent calls to iconv_open() and setlocale().
Comment 4 Henry Hu 2021-09-08 04:25:34 UTC
I've filed PR 258360 and asking other people to take a look.
Comment 5 Henry Hu 2021-09-08 04:28:37 UTC
Meanwhile, we can patch telegram-desktop to workaround the issue.
Before the threads start, maybe we can call setlocale() first. I've tried this with the example program, and it no longer crashes, if I do that.
Comment 6 Oleh Vinichenko 2021-09-08 08:07:36 UTC
i getting this issue too. Notice, that telegram-desktop-3.0.1 is available ( which could bring more of a problems, just for the record newer version exist )
Comment 7 Dmitry Wagin 2021-09-08 08:53:01 UTC
(In reply to Henry Hu from comment #2)

I tried several launches 1/15 worked.
Comment 8 Oleh Vinichenko 2021-09-08 16:31:04 UTC
patch from 258360 fixes this issue, telegram-desktop starting fine, from desktop menu and also if tried from terminal emulator
Comment 9 Gleb Smirnoff freebsd_committer 2021-09-17 18:25:00 UTC
I found out that setlocale() is not supposed to be thread-safe, so fixed the race on the side of telegram-desktop.