Opened 5 years ago

#13335 new Bugs

When using unix domain socket (boost::asio::local::stream_protocol), synchronous write may not respond sometimes on macOS

Reported by: seungrye@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.65.0 Severity: Problem
Keywords: UDS, poll Cc:

Description

In very intermittent situations, synchronous write does not wake up in the following situations:

  1. The server application uses a unix domain socket and accepts and reads asynchronously.
  2. The client application uses a unix domain socket, and there is a thread that performs synchronous write repeatedly. Disconnect and reconnect at any time.

There is no issue when checking on Windows / Mac with tcp socket. UDS (boost::asio::local::stream_protocol) has issue when checking on Mac.

When testing with boost library 1.62.0 and 1.65.0 in macOS 10.12 environment, I confirmed that an issue occurred.

The source code of the function with no response is as follows.

int poll_write (socket_type s, state_type state, boost :: system :: error_code & ec)
{
  if (s == invalid_socket)
  {
    ec = boost :: asio :: error :: bad_descriptor;
    return socket_error_retval;
  }

#if defined (BOOST_ASIO_WINDOWS) \
  || defined (__ CYGWIN__) \
  || defined (__ SYMBIAN32__)
...
#else // defined (BOOST_ASIO_WINDOWS)
      // || defined (__ CYGWIN__)
      // || defined (__ SYMBIAN32__)
  pollfd fds;
  fds.fd = s;
  FDS.Events = POLLOUT;
  FDS.revents = 0;
  int timeout = (state & user_set_non_blocking)? 0: -1;
  clear_last_error ();
  int result = error_wrapper (:: poll (& fds, 1, timeout), ec); //!!! ::poll is not wakeup even if socket cancelled and closed
#endif // defined (BOOST_ASIO_WINDOWS)
       // || defined (__ CYGWIN__)
       // || defined (__ SYMBIAN32__)
...
}

Attached test project. (xcode 8.3 project)

The following settings should be changed as appropriate.

  • Modify the "Link Binary With Libraries" of "Build Phases" as appropriate for both server / client projects.
  • Modify the "Header Search Paths" and "Library Search Path" of the Build Settings as appropriate for both server / client projects.

I do not speak English well so I used Google translation. Therefore, the contents may be awkward. I hope you understand. And, I hope this issue is resolved.

Note. I used the compiled library. Compilation builds version 1.65.0 using the ofxOSXBoost (on GitHub) script (build-libc ++ withBitcode).

Attachments (1)

boost_asio_uds_poll_not_response.zip (134.6 KB ) - added by seungrye@… 5 years ago.
xcode project that reproduct issue.

Download all attachments as: .zip

Change History (1)

by seungrye@…, 5 years ago

xcode project that reproduct issue.

Note: See TracTickets for help on using tickets.