[CONC-591] C connector ignoring SIGPIPE Created: 2022-05-20  Updated: 2023-12-25

Status: Open
Project: MariaDB Connector/C
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Corey Hickey Assignee: Georg Richter
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Debian Unstable
libmariadb from Debian package, version 10.6.7-3+b1



 Description   

Hi,

I have encountered an issue where a perl script which uses the MariaDB C connector (via DBD::MariaDB or DBD::mysql) ends up ignoring SIGPIPE. This results in problems such as:

  • continuing to run even when the pipeline is broken
  • printing an error on exit

I am pretty sure that I tracked this down to code in the C connector introduced in this commit:
https://github.com/mariadb-corporation/mariadb-connector-c/commit/1cefbbecb929b4b4a67b0ac23058ab0167e1c6d6#diff-478b1bbb2170532b687be58bd28e9850ccc0b9a6aec137eb8fff7b8e6d1107bbR3460

A backtrace seems to confirm this (note the ignore_sigpipe() at #4):

(gdb) bt
#0  0x00007ffff7cab9f2 in __GI___libc_sigaction (sig=sig@entry=13, act=act@entry=0x7fffffffd950, 
    oact=oact@entry=0x7fffffffd9f0) at ../sysdeps/unix/sysv/linux/sigaction.c:58
#1  0x00007ffff7cabb25 in __GI___sigaction (sig=sig@entry=13, act=act@entry=0x7fffffffd950, oact=oact@entry=0x7fffffffd9f0)
    at ../nptl/sigaction.c:30
#2  0x00007ffff7cab6e5 in __bsd_signal (sig=sig@entry=13, handler=handler@entry=0x1) at ../sysdeps/posix/signal.c:45
#3  0x00007ffff7cab73b in __bsd_signal (sig=sig@entry=13, handler=handler@entry=0x1) at ../sysdeps/posix/signal.c:35
#4  0x00007ffff78ca025 in ignore_sigpipe () at ./libmariadb/libmariadb/mariadb_lib.c:3842
#5  mysql_once_init () at ./libmariadb/libmariadb/mariadb_lib.c:3898
#6  mysql_once_init () at ./libmariadb/libmariadb/mariadb_lib.c:3851
#7  0x00007ffff7e5b610 in __pthread_once_slow (once_control=0x7ffff78f7b6c <init_once>, 
    init_routine=0x7ffff78c9fb0 <mysql_once_init>) at pthread_once.c:116
#8  0x00007ffff7904f1d in ?? () from /usr/lib/x86_64-linux-gnu/perl5/5.34/auto/DBD/MariaDB/MariaDB.so
#9  0x00007ffff7907f2c in ?? () from /usr/lib/x86_64-linux-gnu/perl5/5.34/auto/DBD/MariaDB/MariaDB.so
#10 0x00007ffff7901ef0 in ?? () from /usr/lib/x86_64-linux-gnu/perl5/5.34/auto/DBD/MariaDB/MariaDB.so
#11 0x0000555555667877 in Perl_pp_entersub ()
#12 0x000055555565df36 in Perl_runops_standard ()
#13 0x00005555555c1f9d in Perl_call_sv ()
#14 0x00007ffff79310b9 in XS_DBI_dispatch () from /usr/lib/x86_64-linux-gnu/perl5/5.34/auto/DBI/DBI.so
#15 0x0000555555667877 in Perl_pp_entersub ()
#16 0x000055555565df36 in Perl_runops_standard ()
#17 0x00005555555ca36c in perl_run ()
#18 0x000055555559d4c2 in main ()

I filed a bug with DBD::MariaDB first, but word there is that the C connector should not be ignoring SIGPIPE.
https://github.com/perl5-dbi/DBD-MariaDB/issues/170

It seems like this behavior must exist for an intended purpose, but I don't know what that would be. Even if there is a good reason to ignore SIGPIPE, it does have some undesired consequences.

Thanks,
Corey



 Comments   
Comment by Pali [ 2023-08-23 ]

georg any comments for this issue?

Comment by Pali [ 2023-11-20 ]

This issue really needs to be fixed in MariaDB C connector. It is really hard or maybe impossible to fix it in the application which uses MariaDB C connector library.

I this comment I wrote all details about this issue and how to fix it:
https://github.com/perl5-dbi/DBD-MariaDB/pull/196#issuecomment-1710697577

Comment by Pali [ 2023-11-20 ]

I think that the fix for MariaDB C connector could be simple. When MSG_NOSIGNAL is supported or SO_NOSIGPIPE is supported or Windows is used then do not call ignore_sigpipe(). This should be enough as MariaDB C connector is already using MSG_NOSIGNAL or SO_NOSIGPIPE when supported to prevent triggering SIGPIPE when writing to disconnected socket.

Comment by Pali [ 2023-12-25 ]

georg , otto any comments for this issue?

Generated at Thu Feb 08 03:06:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.