Qpid
  1. Qpid
  2. QPID-2367

Early Initialization of File Descriptors Conflicts With Daemon Best Practices

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.5
    • Fix Version/s: 0.19
    • Component/s: C++ Client
    • Labels:
      None
    • Environment:

      Linux (possibly all UNIX), c+, g+

      Description

      At least one file descriptor (in qpid/sys/epoll/EpollPoller.*) in the c++ client is global and declared as static. In programs linked against the c++ qpid libs g++ generates code for allocation and, more importantly, initialization of these descriptors that occurs before main(). You can confirm this with gdb by breakpointing both the initialization and main() (the initialization break is hit first).

      On the other hand, the canonical recipe for creating a UNIX daemon calls for the closing of all open file descriptors after fork()ing (where the fork() certainly occurs after main()). While not an absolute requirement, closing all open file descriptors is considered a best practice. A loop to close all descriptors is also common in boilerplate daemon creation code and has undoubtedly been cut-and-pasted into numerous daemons.

      The net effect is that the typical daemon will close the file descriptor opened before main() in the c++ client library. In the case of the epoll code this manifests as an inability to connect to the broker.

      A fix for this would be to defer the initialization of the file descriptor (perhaps via the Singleton pattern or a move of the variables into a class member).

        Activity

        Jason Schlauch created issue -
        Andrew Stitcher made changes -
        Field Original Value New Value
        Assignee Andrew Stitcher [ astitcher ]
        Andrew Stitcher made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 0.19 [ 12322452 ]
        Resolution Fixed [ 1 ]
        Justin Ross made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Andrew Stitcher
            Reporter:
            Jason Schlauch
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development