Я создаю пример веб-калькулятора, где все клиенты должны немедленно увидеть обновления, которые делают другие клиенты.Локально это работает прекрасно, однако при развертывании на клиентском компьютере AWS EC2 запросы на обновление до веб-сокета в некоторых случаях не выполняются как в Chrome (77.x), так и в Firefox (60.x).Насколько я понимаю, сервер блокирует все попытки обновить его, а затем клиент отключается по истечении времени ожидания.
needs.txt:
alembic==1.1.0
Click==7.0
dnspython==1.16.0
eventlet==0.25.1
Flask==1.1.1
Flask-Migrate==2.5.2
Flask-Script==2.0.6
Flask-SocketIO==4.2.1
Flask-SQLAlchemy==2.4.0
greenlet==0.4.15
itsdangerous==1.1.0
Jinja2==2.10.1
Mako==1.1.0
MarkupSafe==1.1.1
monotonic==1.5
psycopg2==2.8.3
psycopg2-binary==2.8.3
python-dateutil==2.8.0
python-dotenv==0.10.3
python-editor==1.0.4
python-engineio==3.9.3
python-socketio==4.3.1
six==1.12.0
SQLAlchemy==1.3.7
Werkzeug==0.15.5
client =socket.io 2.2.0
Код сервера:
import eventlet
eventlet.monkey_patch()
#...other imports...
socketio = SocketIO(application, logger=True, engineio_logger=True)
@socketio.on('json')
def get_new_equation_item(someJson):
try:
send(someJson, json=True, broadcast=True, include_self=False)
#Adding new equation to the database
equation_item = Calculation(body=someJson["emitItem"])
db.session.add(equation_item)
db.session.commit()
except:
error = "Incorrect data from the client"
flash(error, 'error')
return render_template('calc_index.html')
#...other code...
socketio.run(application, host='0.0.0.0', debug=True, use_reloader=False)
Журналы клиентов: вы можете проверить по http://ec2 -54-146-7-208.compute-1.amazonaws.com: 5000
Журналы сервера:
24.118.131.176 - - [19/Sep/2019 16:15:33] "GET /socket.io/?EIO=3&transport=polling&t=MrAJSFH&sid=0784c7202fc64d7fbb6d130bf574c0e5 HTTP/1.1" 400 186 60.001675
89b7a287731d4232b05c5efb59439337: Sending packet OPEN data {'sid': '89b7a287731d4232b05c5efb59439337', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
client connected: 9
89b7a287731d4232b05c5efb59439337: Sending packet MESSAGE data 0
24.118.131.176 - - [19/Sep/2019 16:15:34] "GET /socket.io/?EIO=3&transport=polling&t=MrAJh6W HTTP/1.1" 200 349 0.001331
(25584) accepted ('24.118.131.176', 39652)
89b7a287731d4232b05c5efb59439337: Received request to upgrade to websocket
24.118.131.176 - - [19/Sep/2019 16:15:34] "GET /socket.io/?EIO=3&transport=polling&t=MrAJh8g&sid=89b7a287731d4232b05c5efb59439337 HTTP/1.1" 200 183 0.113250
Traceback (most recent call last):
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/wsgi.py", line 566, in handle_one_response
result = self.application(self.environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/flask/app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/flask_socketio/__init__.py", line 46, in __call__
start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/middleware.py", line 60, in __call__
return self.engineio_app.handle_request(environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/socketio/server.py", line 534, in handle_request
return self.eio.handle_request(environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/server.py", line 366, in handle_request
environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/socket.py", line 106, in handle_get_request
start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/socket.py", line 146, in _upgrade_websocket
return ws(environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/async_drivers/eventlet.py", line 20, in __call__
return super(WebSocketWSGI, self).__call__(environ, start_response)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/websocket.py", line 130, in __call__
self.handler(ws)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/engineio/socket.py", line 171, in _websocket_handler
pkt = ws.wait()
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/websocket.py", line 788, in wait
for i in self.iterator:
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/websocket.py", line 643, in _iter_frames
message = self._recv_frame(message=fragmented_message)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/websocket.py", line 669, in _recv_frame
header = recv(2)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/websocket.py", line 578, in _get_bytes
d = self.socket.recv(numbytes - len(data))
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/greenio/base.py", line 366, in recv
return self._recv_loop(self.fd.recv, b'', bufsize, flags)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/greenio/base.py", line 360, in _recv_loop
self._read_trampoline()
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/greenio/base.py", line 331, in _read_trampoline
timeout_exc=socket_timeout('timed out'))
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/greenio/base.py", line 210, in _trampoline
mark_as_closed=self._mark_as_closed)
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/hubs/__init__.py", line 159, in trampoline
return hub.switch()
File "/home/ec2-user/venvs/sezzle-calc/lib/python3.7/site-packages/eventlet/hubs/hub.py", line 298, in switch
return self.greenlet.switch()
socket.timeout: timed out
24.118.131.176 - - [19/Sep/2019 16:16:34] "GET /socket.io/?EIO=3&transport=websocket&sid=89b7a287731d4232b05c5efb59439337 HTTP/1.1" 500 0 60.056104
Client disconnected: 9
89b7a287731d4232b05c5efb59439337: Client is gone, closing socket
24.118.131.176 - - [19/Sep/2019 16:16:34] "GET /socket.io/?EIO=3&transport=polling&t=MrAJhBM&sid=89b7a287731d4232b05c5efb59439337 HTTP/1.1" 400 186 60.001529
2736a74a53514ed18127c17d6b5ed51f: Sending packet OPEN data {'sid': '2736a74a53514ed18127c17d6b5ed51f', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
client connected: 9
2736a74a53514ed18127c17d6b5ed51f: Sending packet MESSAGE data 0
24.118.131.176 - - [19/Sep/2019 16:16:35] "GET /socket.io/?EIO=3&transport=polling&t=MrAJw3v HTTP/1.1" 200 349 0.001351
(25584) accepted ('24.118.131.176', 39654)
2736a74a53514ed18127c17d6b5ed51f: Received request to upgrade to websocket
24.118.131.176 - - [19/Sep/2019 16:16:35] "GET /socket.io/?EIO=3&transport=polling&t=MrAJw5e&sid=2736a74a53514ed18127c17d6b5ed51f HTTP/1.1" 200 183 0.106838
^Cwsgi exiting
2736a74a53514ed18127c17d6b5ed51f: Failed websocket upgrade, expected UPGRADE packet, received None instead.
24.118.131.176 - - [19/Sep/2019 16:16:49] "GET /socket.io/?EIO=3&transport=websocket&sid=2736a74a53514ed18127c17d6b5ed51f HTTP/1.1" 200 0 13.647335
Спасибо.Пожалуйста, дайте мне знать, если необходима дополнительная информация