Without gdb it runs fine. But when I start the ddnet server using gdb.
gdb ./DDNet-Server
It runs fine at first but then it crashes. The crashes can happen hours after the server started. The crash seems to come from curl.
2023-03-02 19:37:25 I chat: *** 'nameless tee' has left the game (Timeout Protection over)
2023-03-02 19:37:25 I game: leave player='0:nameless tee'
[New Thread 0x7fffe6ffd700 (LWP 4022525)]
[Thread 0x7fffe6ffd700 (LWP 4022525) exited]
Thread 6 "DDNet-Server" received signal SIGPIPE, Broken pipe.
[Switching to Thread 0x7fffe77fe700 (LWP 3934801)]
__libc_write (nbytes=24, buf=0x7fffd80c0aa3, fd=14) at ../sysdeps/unix/sysv/linux/write.c:26
26 ../sysdeps/unix/sysv/linux/write.c: No such file or directory.
(gdb) bt
#0 __libc_write (nbytes=24, buf=0x7fffd80c0aa3, fd=14) at ../sysdeps/unix/sysv/linux/write.c:26
#1 __libc_write (fd=14, buf=0x7fffd80c0aa3, nbytes=24) at ../sysdeps/unix/sysv/linux/write.c:24
#2 0x00007ffff7d39605 in ?? () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
#3 0x00007ffff7d3476a in ?? () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
#4 0x00007ffff7d337c4 in ?? () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
#5 0x00007ffff7d33c83 in BIO_write () from /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
#6 0x00007ffff74df91a in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
#7 0x00007ffff74e0809 in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
#8 0x00007ffff74ea1da in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
#9 0x00007ffff74e8425 in ?? () from /usr/lib/x86_64-linux-gnu/libssl.so.1.1
#10 0x00007ffff7c42cd2 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#11 0x00007ffff7c42d31 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#12 0x00007ffff7c4960b in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#13 0x00007ffff7bff2aa in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#14 0x00007ffff7c1d720 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#15 0x00007ffff7c1eab1 in ?? () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#16 0x00007ffff7c1f286 in curl_multi_perform () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#17 0x00007ffff7bf5a93 in curl_easy_perform () from /usr/lib/x86_64-linux-gnu/libcurl.so.4
#18 0x000055555568e4cf in CHttpRequest::RunImpl (this=0x555555ab7c10, pUser=0x7fffd8018f80) at /home/galactic/git/ddnet/src/engine/shared/http.cpp:295
#19 0x000055555568de05 in CHttpRequest::Run (this=0x555555ab7c10) at /home/galactic/git/ddnet/src/engine/shared/http.cpp:161
#20 0x000055555569267d in CJobPool::RunBlocking (pJob=0x555555ab7c10) at /home/galactic/git/ddnet/src/engine/shared/jobs.cpp:118
#21 0x000055555568a7a7 in IEngine::RunJobBlocking (pJob=0x555555ab7c10) at /home/galactic/git/ddnet/src/engine/shared/engine.cpp:124
#22 0x000055555559f6c6 in CRegister::CProtocol::CJob::Run (this=0x555555aafec0) at /home/galactic/git/ddnet/src/engine/server/register.cpp:417
#23 0x000055555569267d in CJobPool::RunBlocking (pJob=0x555555aafec0) at /home/galactic/git/ddnet/src/engine/shared/jobs.cpp:118
#24 0x00005555556923a8 in CJobPool::WorkerThread (pUser=0x5555559f4540) at /home/galactic/git/ddnet/src/engine/shared/jobs.cpp:73
#25 0x00005555556b9cfc in thread_run (user=0x5555559f68f0) at /home/galactic/git/ddnet/src/base/system.cpp:753
#26 0x00007ffff772aea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#27 0x00007ffff764aa2f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb)
I added signal(SIGPIPE, SIG_IGN);
to the code but it did not help.
But when I start the ddnet server using gdb <...> it crashes.
It isn't a crash, it's a breakpoint. gdb stops a program execution when a signal is raised regardless if a signal is ignored by a program. If you don't want gdb to stop disable its signal handlers in gdb prompt:
gdb> handle all nostop pass
Or
gdb> handle SIGPIPE nostop pass
SIGPIPE
is a very often raised symbol when socket API is used. Therefore you might want to add the last line to the file ~/.gdbinit
.