Skip to content

Commit d5d91ac

Browse files
committed
Make error hint from bind() failure more accurate
The hint "Is another postmaster already running ..." should only be printed for errors that are really about something else already using the address. In other cases it is misleading. So only show that hint if errno == EADDRINUSE. Also, since Unix-domain sockets in the file-system namespace never report EADDRINUSE for an existing file (they would just overwrite it), the part of the hint saying "If not, remove socket file \"%s\" and retry." can never happen, so remove it. Unix-domain sockets in the abstract namespace can report EADDRINUSE, but in that case there is no file to remove, so the hint doesn't work there either. Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://www.postgresql.org/message-id/flat/6dee8574-b0ad-fc49-9c8c-2edc796f0033@2ndquadrant.com
1 parent c9f0624 commit d5d91ac

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/backend/libpq/pqcomm.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -530,18 +530,20 @@ StreamServerPort(int family, const char *hostName, unsigned short portNumber,
530530
err = bind(fd, addr->ai_addr, addr->ai_addrlen);
531531
if (err < 0)
532532
{
533+
int saved_errno = errno;
534+
533535
ereport(LOG,
534536
(errcode_for_socket_access(),
535537
/* translator: first %s is IPv4, IPv6, or Unix */
536538
errmsg("could not bind %s address \"%s\": %m",
537539
familyDesc, addrDesc),
538-
(IS_AF_UNIX(addr->ai_family)) ?
539-
errhint("Is another postmaster already running on port %d?"
540-
" If not, remove socket file \"%s\" and retry.",
541-
(int) portNumber, service) :
542-
errhint("Is another postmaster already running on port %d?"
543-
" If not, wait a few seconds and retry.",
544-
(int) portNumber)));
540+
saved_errno == EADDRINUSE ?
541+
(IS_AF_UNIX(addr->ai_family) ?
542+
errhint("Is another postmaster already running on port %d?",
543+
(int) portNumber) :
544+
errhint("Is another postmaster already running on port %d?"
545+
" If not, wait a few seconds and retry.",
546+
(int) portNumber)) : 0));
545547
closesocket(fd);
546548
continue;
547549
}

0 commit comments

Comments
 (0)