Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdns_control's nonblocking connection to the socket is not correct #14054

Open
Habbie opened this issue Apr 9, 2024 · 0 comments
Open

pdns_control's nonblocking connection to the socket is not correct #14054

Habbie opened this issue Apr 9, 2024 · 0 comments

Comments

@Habbie
Copy link
Member

Habbie commented Apr 9, 2024

DynMessenger::DynMessenger uses timed_connect which calls connect once, assuming it will either get

  • 0 - the connection succeeded
  • EINPROGRESS - the connection is pending, so we call select and assume that when that returns writability, we are connected
  • any other error - the connection failed

However, connect(2) (from Linux man-pages 6.03) notes:

EINPROGRESS
The socket is nonblocking and the connection cannot be completed immediately. (UNIX domain sockets failed with EAGAIN instead.)

The control socket is a UNIX socket, so this code is wrong. Usually, the control socket has room in the accept backlog, so connections do succeed. But if the control thread is tied up (which might be a bug in itself), the backlog may fill, and non blocking connections will not succeed immediately.

In that situation, we get EAGAIN instead of EINPROGRESS, and return error. If I change the code to handle EAGAIN in the same way as EINPROGRESS, the connection still fails, because apparently select considers the socket writable even when it is not yet connected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant