This is how I connect from the client side:
var proxy = require('socket.io-proxy');
proxy.init('http://x.x.x.x:3128');
var socket = proxy.connect('https://example.com');
I use stbrenner/socket.io-proxy as a proxy wrapper for the socket.io-client
. I use the version from the master branch that have socket.io-client >=2.0.4. Also, I had to patch it to make it work because it didn't include hostname in the request (resulted in 400 error) and also hardcode to use http to connect to squid (despite the origin server address being https) since my squid is listening only http (but still proxying port 443).
The error on the client side:
error: Node connect error Error: xhr poll error
at XHR.Transport.onError (/srv/app/node_modules/engine.io-client/lib/transport.js:68:13)
at Request.<anonymous> (/srv/app/node_modules/engine.io-client/lib/transports/polling-xhr.js:132:10)
at Request.Emitter.emit (/srv/app/node_modules/engine.io-client/node_modules/component-emitter/index.js:145:20)
at Request.onError (/srv/app/node_modules/engine.io-client/lib/transports/polling-xhr.js:314:8)
at Timeout._onTimeout (/srv/app/node_modules/engine.io-client/lib/transports/polling-xhr.js:261:18)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7) severity=400, node_uuid=9ea851cb-e6ee-4dfd-a2cb-3fe2586532d0
My squid configuration:
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
include /etc/squid/conf.d/*.conf
http_access allow localhost
#http_access deny all
http_access allow all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern \/(Packages|Sources)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern \/Release(|\.gpg)$ 0 0% 0 refresh-ims
refresh_pattern \/InRelease$ 0 0% 0 refresh-ims
refresh_pattern \/(Translation-.*)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern . 0 20% 4320
http_upgrade_request_protocols OTHER allow all
debug_options ALL,1 11,3 31,3 65,3
This is the response from the origin server side:
Mon, 21 Nov 2022 12:25:12 GMT engine intercepting request for path "/socket.io/"
Mon, 21 Nov 2022 12:25:12 GMT engine handling "GET" http request "/socket.io/?EIO=3&transport=polling&t=OIQ9alJ&b64=1"
Mon, 21 Nov 2022 12:25:12 GMT engine handshaking client "xbazbwzpPukK7rkVAAIH"
Mon, 21 Nov 2022 12:25:12 GMT engine:socket sending packet "open" ({"sid":"xbazbwzpPukK7rkVAAIH","upgrades":["websocket"],"pingInterval":15000,"pingTimeout":15000})
Mon, 21 Nov 2022 12:25:12 GMT engine:polling setting request
Mon, 21 Nov 2022 12:25:12 GMT engine:socket flushing buffer to transport
Mon, 21 Nov 2022 12:25:12 GMT engine:polling writing "97:0{"sid":"xbazbwzpPukK7rkVAAIH","upgrades":["websocket"],"pingInterval":15000,"pingTimeout":15000}"
Mon, 21 Nov 2022 12:25:12 GMT engine:socket executing batch send callback
Mon, 21 Nov 2022 12:25:12 GMT socket.io:server incoming connection with id xbazbwzpPukK7rkVAAIH
Mon, 21 Nov 2022 12:25:12 GMT socket.io:client connecting to namespace /
Mon, 21 Nov 2022 12:25:12 GMT socket.io:namespace adding socket to nsp /
Mon, 21 Nov 2022 12:25:12 GMT socket.io:socket socket connected - writing packet
Mon, 21 Nov 2022 12:25:12 GMT socket.io:socket joining room xbazbwzpPukK7rkVAAIH
Mon, 21 Nov 2022 12:25:12 GMT socket.io:client writing packet {"type":0,"nsp":"/"}
Mon, 21 Nov 2022 12:25:12 GMT socket.io-parser encoding packet {"type":0,"nsp":"/"}
Mon, 21 Nov 2022 12:25:12 GMT socket.io-parser encoded {"type":0,"nsp":"/"} as 0
Mon, 21 Nov 2022 12:25:12 GMT engine:socket sending packet "message" (0)
Mon, 21 Nov 2022 12:25:12 GMT socketio-auth removing socket from /
Mon, 21 Nov 2022 12:25:12 GMT socket.io:socket joined room xbazbwzpPukK7rkVAAIH
Mon, 21 Nov 2022 12:25:14 GMT engine:polling closing
Mon, 21 Nov 2022 12:25:14 GMT engine:polling transport not writable - buffering orderly close
Mon, 21 Nov 2022 12:25:14 GMT socket.io:client client close with reason ping timeout
Mon, 21 Nov 2022 12:25:14 GMT socket.io:socket closing socket - reason ping timeout
Mon, 21 Nov 2022 12:25:14 GMT socketio-auth Disconnecting socket XVQo3QXVeBEIFrezAAIC
And this is debug logs from squid:
2022/11/21 12:16:57.686 kid1| 11,2| client_side.cc(1357) parseHttpRequest: HTTP Client conn627 local=x.x.x.x:3128 remote=x.x.x.x:57396 FD 15 flags=1
2022/11/21 12:16:57.686 kid1| 11,2| client_side.cc(1358) parseHttpRequest: HTTP Client REQUEST:
---------
GET https://example.com/socket.io/?EIO=3&transport=polling&t=OIQ7i3h&b64=1 HTTP/1.1
user-agent: node-XMLHttpRequest
accept: */*
Host: example.com:443
connection: close
----------
2022/11/21 12:16:57.810 kid1| 11,3| http.cc(2498) httpStart: GET https://example.com/socket.io/?EIO=3&transport=polling&t=OIQ7i0i&b64=1
2022/11/21 12:16:57.810 kid1| 11,2| http.cc(2454) sendRequest: HTTP Server conn625 local=x.x.x.x:51642 remote=z.z.z.z:443 HIER_DIRECT FD 13 flags=1
2022/11/21 12:16:57.810 kid1| 11,2| http.cc(2455) sendRequest: HTTP Server REQUEST:
---------
GET /socket.io/?EIO=3&transport=polling&t=OIQ7i0i&b64=1 HTTP/1.1
User-Agent: node-XMLHttpRequest
Accept: */*
Host: example.com
Via: 1.1 squid-new (squid/5.6)
X-Forwarded-For: x.x.x.x
Cache-Control: max-age=0
Connection: keep-alive
----------
2022/11/21 12:16:57.963 kid1| 11,2| http.cc(1291) readReply: conn625 local=x.x.x.x:51642 remote=z.z.z.z:443 HIER_DIRECT FD 13 flags=1: read failure: (0) No error.
2022/11/21 12:16:57.964 kid1| 11,2| Stream.cc(279) sendStartOfMessage: HTTP Client conn622 local=x.x.x.x:3128 remote=x.x.x.x:49448 FD 11 flags=1
2022/11/21 12:16:57.964 kid1| 11,2| Stream.cc(280) sendStartOfMessage: HTTP Client REPLY:
---------
HTTP/1.1 502 Bad Gateway
Server: squid/5.6
Mime-Version: 1.0
Date: Mon, 21 Nov 2022 12:16:57 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 3629
X-Squid-Error: ERR_READ_ERROR 0
Vary: Accept-Language
Content-Language: en
X-Cache: MISS from squid-new
X-Cache-Lookup: MISS from squid-new:3128
Via: 1.1 squid-new (squid/5.6)
Connection: close
So it seems the origin server tries to write a response and fails for whatever reason.
I set socket.io-client
version to 2.0.3 in the forked socket.io-proxy
and it fixed it for me. Although when I run npm view socket.io-client version
it shows me 4.5.3
🤷🏻♂️ anyway, there's a problem with some version of socket.io-client