Opened 8 years ago

Closed 8 years ago

#1184 closed defect (duplicate)

WebSocket forwarding doesn't work

Reported by: oakkitten@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.11.x
Keywords: websocket Cc:
uname -a: Linux pie 4.4.13+ #894 Mon Jun 13 12:43:26 BST 2016 armv6l GNU/Linux
nginx -V: nginx version: nginx/1.11.8
built by gcc 4.9.2 (Raspbian 4.9.2-10)
built with OpenSSL 1.0.1t 3 May 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_perl_module=dynamic --with-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security' --with-ld-opt=-Wl,-z,relro

Description

Nginx 1.11.4 and 1.11.8, the two versions I tried, seem to be abruptly closing the connection to a WebSocket server after receiving an Upgrade message. Version 1.7 doesn't have this problem with the same config. Incidentally, if Nginx 1.11.8 is compiled with the option "--with-debug", the problem disappears, even if debug logging is not enabled in the config.

Relevant part of the config:

location /weechat {
    proxy_pass http://127.0.0.1:9000/weechat;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_read_timeout 604800;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Real-IP $remote_addr;
}

This is what Weechat, the WebSocket server I'm trying to make play with Nginx, receives from Nginx:

GET /weechat HTTP/1.1
Upgrade: websocket
Connection: upgrade
X-Real-IP: 88.112.200.154
Host: 127.0.0.1:9000
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-GB,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
Sec-WebSocket-Version: 13
Origin: http://www.glowing-bear.org
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: V4QIdH4Gs2wGWwJZPMLsTB==
Pragma: no-cache
Cache-Control: no-cache

This is what Weechat replies:

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: 1AxHE5c5ml+BCGh2aIkyRQK48n4=

After this, Weechat says:

relay: reading data on socket for client 2/weechat/127.0.0.1: error 2245 (connection closed by peer)
relay: disconnected from client 2/weechat/127.0.0.1

Change History (1)

comment:1 by Maxim Dounin, 8 years ago

Resolution: duplicate
Status: newclosed

The "gcc 4.9.2 (Raspbian 4.9.2-10)" compiler is know to miscompile things. Upgrading compiler is known to help, as well as disabling some optimization flags. See ticket #912 for details.

Note: See TracTickets for help on using tickets.