Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection hangs in CLOSE_WAIT state #589

Closed
sirkonst opened this issue Nov 20, 2017 · 4 comments
Closed

Connection hangs in CLOSE_WAIT state #589

sirkonst opened this issue Nov 20, 2017 · 4 comments
Assignees
Labels

Comments

@sirkonst
Copy link

sirkonst commented Nov 20, 2017

Server:

from flask import Flask
from flask_socketio import SocketIO, emit

app = Flask(__name__)
socketio = SocketIO(
    app, manage_session=True, logger=True, engineio_logger=True,
    async_mode='eventlet'
)


@socketio.on('connect')
def connect_handler(*args, **kwargs):
    # !!! If do comment next line problem is not reproduced !!!
    emit('any_signal', {'data': 'Connected'})


if __name__ == '__main__':
    socketio.run(app, port=9999, log_output=True, debug=True)

Client:

import signal

from socketIO_client import SocketIO

signal.alarm(5)  # kill self after 5 seconds

conn = SocketIO('localhost', 9999)
conn.wait()

Logs:

/home/_/develop/ec-wss/.env/bin/python /home/_/develop/ec-wss/simple_server.py
Server initialized for eventlet.
 * Restarting with stat
Server initialized for eventlet.
 * Debugger is active!
 * Debugger PIN: 407-346-791
(26666) wsgi starting up on http://127.0.0.1:9999
(26666) accepted ('127.0.0.1', 49774)
161f43bd70da42589172c840673d7608: Sending packet OPEN data {'sid': '161f43bd70da42589172c840673d7608', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
emitting event "any-signal" to 161f43bd70da42589172c840673d7608 [/]
161f43bd70da42589172c840673d7608: Sending packet MESSAGE data 2["any-signal",{"data":"Connected"}]
161f43bd70da42589172c840673d7608: Sending packet MESSAGE data 0
127.0.0.1 - - [20/Nov/2017 17:57:15] "GET /socket.io/?EIO=3&transport=polling&t=1511189835314-0 HTTP/1.1" 200 417 0.000877
(26666) accepted ('127.0.0.1', 49778)
161f43bd70da42589172c840673d7608: Received request to upgrade to websocket

Socket state:

$ lsof -i -n -P | grep 9999
python    26666 konst    3u  IPv4 10498613      0t0  TCP 127.0.0.1:9999 (LISTEN)
python    26666 konst    6u  IPv4 10499520      0t0  TCP 127.0.0.1:9999->127.0.0.1:49778 (CLOSE_WAIT)

Issue:

Socket in CLOSE_WAIT state will never closed (until restart app). Looks like that upgrade to websocket is hung. It's can case DoS because open sockets is limited resource (in a product count of CLOSE_WAIT always grows :-().

@miguelgrinberg miguelgrinberg self-assigned this Nov 20, 2017
@miguelgrinberg
Copy link
Owner

Thanks. Need to figure out why this happens with the Python client. It does not happen when using the official JS client.

@miguelgrinberg
Copy link
Owner

Can I ask you to retest with the git master branch of python-engineio? I'm getting the websocket connection upgraded successfully after the fix I just put in. Thanks!

@sirkonst
Copy link
Author

Yes! Not reproduced after update python-engineio to master. Thanks!

I hope the release python-engineio with fix does not take long.

@miguelgrinberg
Copy link
Owner

@sirkonst No, I just pushed the release out to pypi. Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants