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

Fail hard when UNIX socket cannot be created #830

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

JelteF
Copy link
Member

@JelteF JelteF commented Apr 21, 2023

When a user requests that a UNIX socket is created and this fails for
some reason we ignored the error. With this change it starts failing
hard when that happens.

This problem is especially bad when so_reuseport is used in combination
with peering, because the peer list would then contain sockets that
don't exist and forwarding cancels would wait for timeout and then fail
silently.

Copy link
Member

@petere petere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that we

src/pooler.c Outdated
@@ -239,7 +239,8 @@ static void create_unix_socket(const char *socket_dir, int listen_port)
unlink(un.sun_path);
}

add_listen(AF_UNIX, (const struct sockaddr *)&un, addrlen);
if (!add_listen(AF_UNIX, (const struct sockaddr *)&un, addrlen))
die("failed to create UNIX socket in directory: %s", socket_dir);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that we should make this an error somehow.

The error leading up to this is something like

WARNING cannot listen on unix:/tmpx/.s.PGSQL.6432: bind(): No such file or directory

so the directory was already mentioned. Also, the way you have phrased it, I would expect the error message to come after the colon, not the directory name. Maybe let's just simplify this to die("failed to create UNIX socket").

I don't think we use the capitalization "UNIX socket" anywhere.

Also, let's consider how this works in PostgreSQL: There, it checks whether at least one TCP/IP socket was created and at least one Unix socket, if configured. The current logic in PgBouncer is that it checks whether at least one socket was created in total. If we are going to touch this, should we make the logic more like PostgreSQL? That would include something like your patch and then another change to check the count of created TCP/IP sockets separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the error message to "failed to create unix socket". Our capitalization of unix socket is inconsistent, using both unix and Unix. But I agree that it's best not to add a third version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, let's consider how this works in PostgreSQL: There, it checks whether at least one TCP/IP socket was created and at least one Unix socket, if configured. The current logic in PgBouncer is that it checks whether at least one socket was created in total. If we are going to touch this, should we make the logic more like PostgreSQL? That would include something like your patch and then another change to check the count of created TCP/IP sockets separately.

For this I created #838

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you add a comment explaining this situation? Commit message contains an explanation but a comment is better (similar to the one in parse_add).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

@JelteF JelteF force-pushed the fail-hard-unix-socket-failure branch 2 times, most recently from e6b83e1 to 44c452e Compare April 25, 2023 13:24
@JelteF JelteF requested a review from petere April 25, 2023 15:40
When a user requests that a UNIX socket is created and this fails for
some reason we ignored the error. This starts failing hard when that
happens.

This problem is especially bad when so_reuseport is used in combination
with peering, because the peer list would then contain sockets that
don't exist and forwarding cancels would wait for timeout and then fail
silently.
@JelteF JelteF requested a review from eulerto April 26, 2023 07:56
@JelteF JelteF force-pushed the fail-hard-unix-socket-failure branch from 44c452e to 97ba16b Compare April 26, 2023 07:57
@JelteF JelteF merged commit d40401f into pgbouncer:master Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants