SocketCluster / socketcluster

Highly scalable realtime pub/sub and RPC framework
https://socketcluster.io
MIT License
6.15k stars 314 forks source link

Socket hung up #428

Open leyue opened 6 years ago

leyue commented 6 years ago

env:

1: ingress rules:

bug:

Most of the time can be connected successfully but some times: (from chrome devtool)

WebSocket connection to 'ws://sprd.nats.service:30001/nats/scc-demo/socketcluster/' failed: WebSocket is closed before the connection is established.

Uncaught SocketProtocolError {name: "SocketProtocolError", message: "Client connection establishment timed out", code: 4007, stack: "SocketProtocolError: Client connection establishme…_communication_01/public/socketcluster.js:1457:18"}

WebSocket connection to 'ws://sprd.nats.service:30001/nats/scc-demo/socketcluster/' failed: Error in connection establishment: net::ERR_NAME_NOT_RESOLVED

Uncaught SocketProtocolError {name: "SocketProtocolError", message: "Socket hung up", code: 1006, stack: "SocketProtocolError: Socket hung up↵ at SCClien…communication_01/public/socketcluster.js:1452:20)"}

leyue commented 6 years ago

add some info: form docker container: ###################################################

socketcluster-sample@1.0.0 start:docker /usr/src node dockerwait.js && node ${SOCKETCLUSTER_MASTER_CONTROLLER:-server.js}

[Busy] Launching SocketCluster

Broker PID: 43 WorkerCluster PID: 53 Worker PID: 59 [Active] SocketCluster started Version: 13.1.7 Environment: prod WebSocket engine: ws Port: 8000 Master PID: 33 Worker count: 1 Broker count: 1

{ SocketProtocolError: Socket hung up at SCSocket._onSCClose (/usr/src/node_modules/scc-broker-client/node_modules/socketcluster-client/lib/scsocket.js:652:15) at SCTransport. (/usr/src/node_modules/scc-broker-client/node_modules/socketcluster-client/lib/scsocket.js:294:12) at SCTransport.Emitter.emit (/usr/src/node_modules/component-emitter/index.js:133:20) at SCTransport._onClose (/usr/src/node_modules/scc-broker-client/node_modules/socketcluster-client/lib/sctransport.js:212:28) at WebSocket.SCTransport.wsSocket.onclose (/usr/src/node_modules/scc-broker-client/node_modules/socketcluster-client/lib/sctransport.js:66:10) at WebSocket.onClose (/usr/src/node_modules/ws/lib/event-target.js:124:16) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) name: 'SocketProtocolError', message: 'Socket hung up', code: 1006 } 1529463542362 - Origin: Worker (PID 59) [Warning] SocketProtocolError: Socket hung up at SCServerSocket._onSCClose (/usr/src/node_modules/socketcluster-server/scserversocket.js:249:17) at WebSocket. (/usr/src/node_modules/socketcluster-server/scserversocket.js:79:10) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at TCP._handle.close [as _onclose] (net.js:554:12) 1529463542648 - Origin: Worker (PID 59) [Warning] SocketProtocolError: Failed to complete handshake at SCServerSocket._onSCClose (/usr/src/node_modules/socketcluster-server/scserversocket.js:249:17) at WebSocket. (/usr/src/node_modules/socketcluster-server/scserversocket.js:79:10) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at TCP._handle.close [as _onclose] (net.js:554:12) 1529463542791 - Origin: Worker (PID 59) [Warning] SocketProtocolError: Failed to complete handshake at SCServerSocket._onSCClose (/usr/src/node_modules/socketcluster-server/scserversocket.js:249:17) at WebSocket. (/usr/src/node_modules/socketcluster-server/scserversocket.js:79:10) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at TCP._handle.close [as _onclose] (net.js:554:12) 1529463543308 - Origin: Worker (PID 59) [Warning] SocketProtocolError: Socket hung up at SCServerSocket._onSCClose (/usr/src/node_modules/socketcluster-server/scserversocket.js:249:17) at WebSocket. (/usr/src/node_modules/socketcluster-server/scserversocket.js:79:10) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at TCP._handle.close [as _onclose] (net.js:554:12) 1529463571382 - Origin: Worker (PID 59) [Warning] SocketProtocolError: Socket hung up at SCServerSocket._onSCClose (/usr/src/node_modules/socketcluster-server/scserversocket.js:249:17) at WebSocket. (/usr/src/node_modules/socketcluster-server/scserversocket.js:79:10) at emitTwo (events.js:126:13) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/usr/src/node_modules/ws/lib/websocket.js:172:10) at Socket.socketOnClose (/usr/src/node_modules/ws/lib/websocket.js:774:15) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at TCP._handle.close [as _onclose] (net.js:554:12)

jondubois commented 6 years ago

These errors seem to indicate that the server could not be reached or it took too long to establish the connection. Maybe there is a load balancer/proxy which is blocking or throttling the connection. You can also get this error if a socket disconnects abruptly without sending a WebSocket close control frame.

It's normal to get these 'Socket hung up' messages from time to time in production though.