poljar / weechat-matrix

Weechat Matrix protocol script written in python
Other
958 stars 120 forks source link

matrix: disconnected from server #240

Open avdb13 opened 3 years ago

avdb13 commented 3 years ago

This is an extremely annoying problem I've been experiencing since I picked up "weechat-matrix" as my native Matrix client again. Every few seconds it disconnects, just to wait 10 seconds before reconnecting. I also don't know what the cause is since I'm the only person on my homeserver (which got enough resources).

poljar commented 3 years ago

There are a couple of closed issues which explain how to mitigate this: https://github.com/poljar/weechat-matrix/issues/27#issuecomment-584323279 https://github.com/poljar/weechat-matrix/issues/69#issuecomment-478168413 https://github.com/poljar/weechat-matrix/issues/123#issuecomment-543573043 https://github.com/poljar/weechat-matrix/issues/195#issuecomment-635544297

avdb13 commented 3 years ago
server {
    listen 80;
    server_name gravitation.me;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name gravitation.me;

    ssl_certificate /etc/letsencrypt/live/gravitation.me/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/gravitation.me/privkey.pem;

    location /_matrix {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        # Nginx by default only allows file uploads up to 1M in size
        # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
        client_max_body_size 10M;
    }
}

# This is used for Matrix Federation
# which is using default TCP port '8448'
server {
    listen 8448;
    server_name gravitation.me;

    ssl_certificate /etc/letsencrypt/live/gravitation.me/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/gravitation.me/privkey.pem;

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

This is my nginx configuration for Matrix. Sorry if this sounds like a stupid question, but which one of the three is the reverse proxy? Which part do I have to alter? I just copied and pasted the commands since this is my first time using nginx.

dkasak commented 3 years ago

In your second server block, place a http2_max_requests N; directive, where N is the number of HTTP requests you want to allow over a single HTTP2 connection before it is closed. On our own server, we set this to 100000 and it's been working fine.

In your case, the section would then look like this:

server {
    listen 443 ssl;
    server_name gravitation.me;

    http2_max_requests 100000;

    ssl_certificate /etc/letsencrypt/live/gravitation.me/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/gravitation.me/privkey.pem;

    location /_matrix {
        proxy_pass http://localhost:8008;
        proxy_set_header X-Forwarded-For $remote_addr;
        # Nginx by default only allows file uploads up to 1M in size
        # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
        client_max_body_size 10M;
    }
}
PiPauwels commented 3 years ago

I've encountered exactly the same problem, but every solution I found here was related to Nginx. Since my homeserver is using Apache Reversed Proxy, I did some digging and found this same solution could be applied for Apache using these steps:

<IfModule mpm_worker_module>
    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    MaxRequestWorkers 150
    MaxConnectionsPerChild 0
</IfModule>
<IfModule mpm_worker_module>
    ServerLimit 250
    StartServers 10
    MinSpareThreads 75
    MaxSpareThreads 250
    ThreadLimit 64
    ThreadsPerChild 32
    MaxRequestWorkers 8000
    MaxConnectionsPerChild 10000
</IfModule>
sudo systemctl stop matrix-synapse
sudo /etc/init.d/apache2 restart
sudo systemctl start matrix-synapse