Issue 8590 - LMDB: Suppress SIGPIPE in mdb_env_copythr on OS X
Summary: LMDB: Suppress SIGPIPE in mdb_env_copythr on OS X
Status: UNCONFIRMED
Alias: None
Product: LMDB
Classification: Unclassified
Component: liblmdb (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-15 19:06 UTC by lmb@cloudflare.com
Modified: 2023-12-24 15:38 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description lmb@cloudflare.com 2017-02-15 19:06:09 UTC
Full_Name: Lorenz Bauer
Version: mdb.master
OS: OS X
URL: https://gist.github.com/lmb/a35e7b9566fa79e7bf971ac21bbb9efb
Submission from: (NULL) (2a06:98c0:1000:8200:b860:273:d664:7f97)


It seems like OS X is not standards compliant wrt SIGPIPE, which breaks
mdb_env_copyfd1.

On mdb.master, I can see the following behaviour on OS X 10.11:

  (gdb) r
  Starting program: /Users/lorenz/dev/openldap/libraries/liblmdb/mtest8
  returning Broken pipe[Inferior 1 (process 6180) exited with code 040]
  (gdb) r
  Starting program: /Users/lorenz/dev/openldap/libraries/liblmdb/mtest8
  returning Broken pipe[Inferior 1 (process 6182) exited with code 040]
  (gdb) r
  Starting program: /Users/lorenz/dev/openldap/libraries/liblmdb/mtest8
  [New Thread 0x1513 of process 6184]
  
  Thread 1 received signal SIGPIPE, Broken pipe.
  0x00007fff91eb7db6 in __psynch_cvwait () from
/usr/lib/system/libsystem_kernel.dylib
  (gdb) info th
    Id   Target Id         Frame
  * 1    Thread 0x1323 of process 6184 0x00007fff91eb7db6 in __psynch_cvwait ()
from   /usr/lib/system/libsystem_kernel.dylib
    2    Thread 0x1513 of process 6184 0x00007fff91eb83c2 in __sigwait () from  
/usr/lib/system/libsystem_kernel.dylib

mtest8 creates a pipe, closes one end and then calls mdb_env_copyfd2 with
CP_COMPACT. Apparently OS X delivers the signal to the entire process.

It seems like the sigwait in the current code sometimes races the notification,
and therefore prevents SIGPIPE.

I found an OS X specific fcntl which fixes this issue. I've attached a patch.

The attached file is derived from OpenLDAP Software. All of the modifications
to
OpenLDAP Software represented in the following patch(es) were developed by
Cloudflare, Inc. Cloudflare, Inc. has not assigned rights and/or interest in
this work to any party. I, Lorenz Bauer am authorized by Cloudflare, Inc., my
employer, to release this work under the following terms.
Cloudflare, Inc. hereby place the following modifications to OpenLDAP Software
(and only these modifications) into the public domain. Hence, these
modifications may be freely used and/or redistributed for any purpose with or
without attribution and/or other notice.
Comment 1 lmb@cloudflare.com 2017-02-23 12:21:44 UTC
I should probably mention that this bug will make compacting copies
lock up on OS X, since the copy thread blocks in sigwait forever if
the process set SIG_IGN on SIGPIPE.

Regards,
Lorenz

Comment 2 Quanah Gibson-Mount 2017-03-17 16:43:21 UTC
moved from Incoming to Software Bugs
Comment 3 lmb@cloudflare.com 2017-05-31 10:12:26 UTC
I've created a test program, available at [1], which will hopefully
help verify this patch.

1: https://gist.github.com/lmb/a35e7b9566fa79e7bf971ac21bbb9efb#file-0002-add-tests-for-sigpipe-behaviour-patch

Best,
Lorenz