getaddrinfo("localhost") can fail depending on the name server configuration, use "127.0.0.0" instead.