Error: Lost connection to server each 60 seconds.

1,438 views
Skip to first unread message

Max Yari

unread,
May 3, 2015, 8:52:01 PM5/3/15
to pee...@googlegroups.com
I'm using `PeerJS-Server` with `node.js express` application.

And as title says, each 60 seconds on client side i am recieving

PeerJS:  Socket closed.
peer
.min.js:1 PeerJS:  ERROR Error: Lost connection to server.

and on the server side
Socket closed: d0eq04zvpc4bo6r0

On the clients side, after catching this error, peer connection is reestablished (by running var peer = new Peer({ }) and rebinding all events). And after next 60 seconds it fails again.
Connecting to peers and sending data (DataConnection) works fine. I'm not doing this reconnections forever, after 3rd one app just falls back on socket connection which is established by Socket.io for all users anyway.
Such a fixed amounts of time looks like that some kind of heartbeat of peerserver socket is failing, yet i do not know how to fix that.

Here's my client peer configuration:

peer = new Peer({
        host: location.host.split(':')[0],
        port: location.host.split(':')[1] ? location.host.split(':')[1] : 80,
        path: '/peerjs',
        debug: 3,
        config: { 'iceServers': [{ url: 'stun:stun01.sipphone.com' },
{ url: 'stun:stun.ekiga.net' },
{ url: 'stun:stun.fwdnet.net' },
{ url: 'stun:stun.ideasip.com' },
{ url: 'stun:stun.iptel.org' },
{ url: 'stun:stun.rixtelecom.se' },
{ url: 'stun:stun.schlund.de' },
{ url: 'stun:stun.l.google.com:19302' },
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'stun:stun2.l.google.com:19302' },
{ url: 'stun:stun3.l.google.com:19302' },
{ url: 'stun:stun4.l.google.com:19302' },
{ url: 'stun:stunserver.org' },
{ url: 'stun:stun.softjoys.com' },
{ url: 'stun:stun.voiparound.com' },
{ url: 'stun:stun.voipbuster.com' },
{ url: 'stun:stun.voipstunt.com' },
{ url: 'stun:stun.voxgratia.org' },
{ url: 'stun:stun.xten.com'}]
        }

Any ideas?

Max Yari

unread,
May 3, 2015, 9:10:20 PM5/3/15
to pee...@googlegroups.com
P.S: there was no problem with 60 second disconenction while testing on local machine, now i pushed my app to VPS (dokku on DigitalOcean) and here we go...

i'm using peer.js server 0.2.8 and latest versions of node.js, express and socket.io.
Also as i already have established socket.io connections, i'am intrested, is there a way to hook peerJS server to existing socket connection (maybe with minor changes to source?). Don't really needthose x2 socket connections if i can avoid it.
Message has been deleted
Message has been deleted
Message has been deleted

Max Yari

unread,
May 9, 2015, 8:35:30 AM5/9/15
to pee...@googlegroups.com
It seems that it was an Nginx problems. Nginx was dropping socke connection each 60 seconds cos of proxy_read_timeout  which has default value of 60 seconds and affects Websockets.
There is 2 ways
1: make a heartbeat sending some packet eachtime within this 60 seconds to sustain websocket conenction as being active, but this way, suposably, means some intrusion in server and client side peerjs source. Also, my sicket.io was working fine as socket.io have out-of-the-box implemented heartbeat.
2:  increase proxy_read_timeout (which i've done, to 86400s), also it seems that proxy_send_timeout 86400s; also need to be added.

Here's my working (atleast so far) nginx config (it's nginx config from dokku, only application server block)

server {
  listen      [::]:80;
  listen      80;
  server_name app.domain.net domain.net ;
  location    / {
    proxy_pass  http://app;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Request-Start $msec;
  }
  proxy_read_timeout 86400s;
  proxy_send_timeout 86400s;
  include /home/dokku/vapp/nginx.conf.d/*.conf;
}
upstream app { server ip:port; }

On Monday, May 4, 2015 at 3:52:01 AM UTC+3, Max Yari wrote:
Reply all
Reply to author
Forward
0 new messages