[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#8590) LMDB: Suppress SIGPIPE in mdb_env_copythr on OS X

Full_Name: Lorenz Bauer
Version: mdb.master
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

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
  (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  

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
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.