Skip to content

Commit

Permalink
Problem: race condition in making socket non-inheritable
Browse files Browse the repository at this point in the history
Solution: create sockets with WSA_FLAG_NO_HANDLE_INHERIT
  • Loading branch information
sigiesec committed May 23, 2018
1 parent 44da0e7 commit 2d9a895
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ zmq::fd_t zmq::open_socket (int domain_, int type_, int protocol_)
type_ |= SOCK_CLOEXEC;
#endif

#if defined ZMQ_HAVE_WINDOWS && defined WSA_FLAG_NO_HANDLE_INHERIT
// if supported, create socket with WSA_FLAG_NO_HANDLE_INHERIT, such that
// the race condition in making it non-inheritable later is avoided
const fd_t s = WSASocket (domain_, type_, protocol_, NULL, 0,
WSA_FLAG_NO_HANDLE_INHERIT);
#else
const fd_t s = socket (domain_, type_, protocol_);
#endif
if (s == retired_fd) {
#ifdef ZMQ_HAVE_WINDOWS
errno = wsa_error_to_errno (WSAGetLastError ());
Expand Down

0 comments on commit 2d9a895

Please sign in to comment.