I am using the XrdCl libraries in a C++ framework which uses libc fork() heavily. When I create a DefaultEnv object, for example to set the log level, the static methods defined there somehow interfere with fork() and cause it to hang. A simple example program to recreate the problem:

> cat fork.cpp
#include <sys/wait.h>
#include <XrdCl/XrdClDefaultEnv.hh>
#include <XrdCl/XrdClLog.hh>

int main () {
  XrdCl::DefaultEnv env;
  XrdCl::Log *log = XrdCl::DefaultEnv::GetLog();
  log->SetLevel(XrdCl::Log::DumpMsg);

  int status;
  pid_t pid;

  pid = fork ();
  if (pid == 0) {
    // child
    sleep(1);
  } else if (pid < 0) {
    // The fork failed.  Report failure.
    status = -1;
  } else {
    // This is the parent process.  Wait for the child to complete.
    if (waitpid (pid, &status, 0) != pid)
      status = -1;
  }
  return status;
}
> g++ -o fork -I /usr/include/xrootd -l XrdCl -l pthread fork.cpp
> ./fork 
[2019-03-04 14:18:58.927546 +0100][Debug  ][Utility           ] In the prepare fork handler for process 1576837
[2019-03-04 14:18:58.927602 +0100][Debug  ][Utility           ] Running the prepare fork handler for process 1576837
[2019-03-04 14:18:58.927609 +0100][Debug  ][Utility           ] Locking File and FileSystem objects for process: 1576837
[2019-03-04 14:18:58.927615 +0100][Debug  ][Utility           ] In the prepare fork handler for process 1576837
[2019-03-04 14:18:58.927620 +0100][Debug  ][Utility           ] Running the prepare fork handler for process 1576837

The process hangs at this point. Removing the XrdCl part, i.e. commenting out the first 3 lines of main(), allows the process to complete normally.

Attaching to the hanging process, one can see that the XrdCl prepare handler is being used:

#0  0x00007ff6914be4ed in __lll_lock_wait () from /lib64/libpthread.so.0
#1  0x00007ff6914b9dcb in _L_lock_883 () from /lib64/libpthread.so.0
#2  0x00007ff6914b9c98 in pthread_mutex_lock () from /lib64/libpthread.so.0
#3  0x00007ff6917834b8 in XrdCl::ForkHandler::Prepare() () from /lib64/libXrdCl.so.2
#4  0x00007ff6917087f0 in prepare () from /lib64/libXrdCl.so.2
#5  0x00007ff690988eac in fork () from /lib64/libc.so.6
#6  0x0000000000400fb7 in main ()

Is there a way to avoid this problem?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/xrootd/xrootd","title":"xrootd/xrootd","subtitle":"GitHub repository","main_image_url":"https://github.githubassets.com/images/email/message_cards/header.png","avatar_image_url":"https://github.githubassets.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/xrootd/xrootd"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"XrdCl::DefaultEnv interferes with fork() (#919)"}],"action":{"name":"View Issue","url":"https://github.com/xrootd/xrootd/issues/919"}}} [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/xrootd/xrootd/issues/919", "url": "https://github.com/xrootd/xrootd/issues/919", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

Use REPLY-ALL to reply to list

To unsubscribe from the XROOTD-DEV list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=XROOTD-DEV&A=1