You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am using this library and from time to time, I have registered that my websocket stopped working. I tried to debug it, and find out, socket is missing but no error message is logged.
Now, lets show some example. I dockerized (the same problem was discovered even when the application was not dockerized) my application and find out via netstat command, I have opened socket with destination port 443:
When I check it with my websocket app that did not receive any messages for a long time, I find out there is no opened socket, but also no errors in output (I checked docker logs and also my app logs):
docker exec mywebsocket /bin/netstat -tpn
My fix:
I implemented function check_websocket_connection() and insert it inside while loop after sleep:
import os
import psutil
import logging
logger = logging.getLogger()
process = psutil.Process(os.getpid())
def check_websocket_connection():
for connection in process.connections():
if connection.raddr.port == 443 and connection.status == 'ESTABLISHED':
logger.debug('Connections on port 433 is established.')
return True
return False
while True:
# Do other things in the meantime here...
time.sleep(1)
if not check_websocket_connection():
logger.error('Missing socket')
break
It check every second if there exists some connection with destination port 443 created by programs PID. I know, it can't be used if PID use more than one connection with port 443, but I need only this connection so it works.
This is just snippet, I created whole class with logging, I hope I did not make any mistake here.
It works for now, but is there a better way how to solve it?
The text was updated successfully, but these errors were encountered:
Issue:
Hi, I am using this library and from time to time, I have registered that my websocket stopped working. I tried to debug it, and find out, socket is missing but no error message is logged.
Now, lets show some example. I dockerized (the same problem was discovered even when the application was not dockerized) my application and find out via
netstat
command, I have opened socket with destination port443
:When I check it with my websocket app that did not receive any messages for a long time, I find out there is no opened socket, but also no errors in output (I checked docker logs and also my app logs):
My fix:
I implemented function
check_websocket_connection()
and insert it inside while loop after sleep:It check every second if there exists some connection with destination port 443 created by programs PID. I know, it can't be used if PID use more than one connection with port 443, but I need only this connection so it works.
This is just snippet, I created whole class with logging, I hope I did not make any mistake here.
It works for now, but is there a better way how to solve it?
The text was updated successfully, but these errors were encountered: