socket.io-client doesn't flush

2019-09-01 11:54发布

I have a connection via socket.io that gives me problems.

On my page under the $(document).ready I setup my socket:

socket = io.connect(...)

I also have a:

socket.on('connect', function() {
    socket.emit(...); // initial request
});

Now as far as this I have no problems. I always receive an expected response on "initial request". After this I want to send another request:

$("#myButton").click(function(){
    socket.emit(...);
    socket.emit(...);
});

In about 1/10 times this will not get a response, actually it will never even send the request.

Looking in the socket.io log gives me this:

socket.io-client:manager writing packet ...
socket.io-parser encoding packet ...
socket.io-parser encoding packet ...
socket.io-client:manager writing packet ...
socket.io-parser encoding packet ...
socket.io-parser encoding packet ...
socket.io-client:socket flushing 2 packets in socket

With the only exception that the non working version doesn't show the flushing row.

So for some reason the socket-io doesn't seem to flush in certain situations...

for the non working version the log the continues after some seconds (>20)

engine.io-client:socket writing ping packet - expected ping within 60000ms
engine.io-client:socket probe transport "websocket" failed because of error: transport closed
engine.io-client:socket socket error {"type":"TransportError","description":504}
....

There seem to be no difference if the time between the "initial request" and the following request is long or short (>30s or <2s).

On the back end I use flask, nginx, etc.

Update

So further investigation show that I have a difference even before I click the myButton. Locking in the logs prior to the click showed me the following:

engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xOEY&sid=...
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" opened
engine.io-client:socket probe transport "websocket" pong
engine.io-client:socket pausing current transport "polling"
engine.io-client:polling we are currently polling - waiting to pause
engine.io-client:polling polling got data ArrayBuffer
engine.io-client:socket socket receive: type "noop", data "undefined"
engine.io-client:polling pre-pause polling complete
engine.io-client:polling paused
engine.io-client:socket changing transport and sending upgrade packet

While the failing case got this log:

engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xTeA&sid=...
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" opened
engine.io-client:polling polling got data ArrayBuffer
engine.io-client:socket socket receive: type "noop", data "undefined"
engine.io-client:polling polling
engine.io-client:polling-xhr xhr poll
engine.io-client:polling-xhr xhr open GET: https://localhost/socket.io/?EIO=3&transport=polling&t=LD_xTh-&sid=c1bc5c38a1f54c0297a79d583800f506
engine.io-client:polling-xhr xhr data null
engine.io-client:socket probe transport "websocket" pong
engine.io-client:socket pausing current transport "polling"
engine.io-client:polling we are currently polling - waiting to pause

So... not really sure what this means, could it be that when the websocket pong is delayed the communication gets screwed up? but why would there be a delay in the pong?

UPDATE This is the software I'm running on the server (updated, and no improvement)

Babel==2.2.0
blinker==1.4
eventlet==0.18.4
Flask==0.10.1
Flask-Babel==0.9
Flask-Login==0.3.2
Flask-Principal==0.4.0
Flask-SocketIO==1.0
greenlet==0.4.9
gunicorn==19.4.5
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
paho-mqtt==1.1
py==1.4.31
pytest==2.9.1
python-engineio==0.9.0
python-socketio==1.2
pytz==2016.2
selenium==2.48.0
six==1.10.0
speaklater==1.3
Werkzeug==0.11.4

0条回答
登录 后发表回答