Server won't start on alpine/libmusl without IPv6. (#8655)

listenToPort attempts to gracefully handle and ignore certain errors but does not store errno prior to logging, which in turn calls several libc functions that may overwrite errno.

This has been discovered due to libmusl strftime() always returning with errno set to EINVAL, which resulted with docker-library/redis#273.
This commit is contained in:
Yossi Gottlieb 2021-03-16 11:20:03 +02:00 committed by GitHub
parent e1d98bca5a
commit df5f543b65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3053,14 +3053,15 @@ int listenToPort(int port, socketFds *sfd) {
sfd->fd[sfd->count] = anetTcpServer(server.neterr,port,addr,server.tcp_backlog);
}
if (sfd->fd[sfd->count] == ANET_ERR) {
int net_errno = errno;
serverLog(LL_WARNING,
"Could not create server TCP listening socket %s:%d: %s",
addr, port, server.neterr);
if (errno == EADDRNOTAVAIL && optional)
if (net_errno == EADDRNOTAVAIL && optional)
continue;
if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
errno == EAFNOSUPPORT)
if (net_errno == ENOPROTOOPT || net_errno == EPROTONOSUPPORT ||
net_errno == ESOCKTNOSUPPORT || net_errno == EPFNOSUPPORT ||
net_errno == EAFNOSUPPORT)
continue;
/* Rollback successful listens before exiting */