Synapse: Tons of `connect() failed (111: Connection refused) while connecting to upstream` in nginx log

Created on 24 Apr 2017  Â·  7Comments  Â·  Source: matrix-org/synapse

I have Synapse set up with a nginx as a reverse proxy on the client port. I was looking at my nginx logs for other reasons, but realized they are filled with errors line like this:

connect() failed (111: Connection refused) while connecting to upstream, client: <myclientip>, server: <mymatrixHShostname>, request: "GET /_matrix/client/…"

This is quite annoying by itself, but might even be a symptom for an actual issue.

Most helpful comment

My issue seems to be that localhost is sometimes resolved as IPv4 and sometimes as IPv6, when it's resolved as IPv6 there is nobody home to handle the request and it fails. I just changed localhost to 127.0.0.1 in the conf and it has stopped for a while...

All 7 comments

Please post your nginx config in order to rule out a misconfiguration.

Regards

Sorry for the delay. A nging misconfiguration is likely indeed, I have no knowledge in proxy-passing configuration. That being said, I’ve mostly used the conf from the README. My file:

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name <mymatrixHShostname>;

    ssl_certificate /etc/letsencrypt/live/<mymatrixHShostname>/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/<mymatrixHShostname>/privkey.pem;
    include ssl.conf;

    location /_matrix {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    access_log /var/log/nginx/matrix.log;
}

Getting this on my side as well, not a crazy number of open file descriptors either.

My issue seems to be that localhost is sometimes resolved as IPv4 and sometimes as IPv6, when it's resolved as IPv6 there is nobody home to handle the request and it fails. I just changed localhost to 127.0.0.1 in the conf and it has stopped for a while...

Having the same issue. This is my nginx config. It was working for a few hours but now fails

server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        ssl_certificate /etc/letsencrypt/live/MYDOMAIN/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/MYDOMAIN/privkey.pem;

        server_name MYDOMAIN;
        location /_matrix {
                proxy_pass http://0.0.0.0:8008;
                proxy_set_header X-Forwarded-For $remote_addr;

        }
}

Restarting synapse made the error go away.

this just means your synapse is down or not listening on the configured port / IP address. I don't think there's much to do here.

@Qwertie- have you redacted your internal ip address to http://0.0.0.0:8008;? The IP 0.0.0.0 is a null route and wont go anywhere. If it is indeed specified as such in config and it's running on the same machine change it to the loopback IP of 127.0.0.1

Was this page helpful?
0 / 5 - 0 ratings