WebSocket-for-Python icon indicating copy to clipboard operation
WebSocket-for-Python copied to clipboard

When I cause an error inside received_message, it gets silenced and the socket gets closed

Open RobbieGM opened this issue 8 years ago • 0 comments

I have an error in one of my larger programs that occurs somewhere in received_message or in a function that is called inside of that function. The error is pretty hard to pin down because when it happens it just gets silenced so I can't figure out where it is, and also the socket gets closed. I wrote a smaller program to simulate this and got the same results. Here's the smaller program:

from ws4py.server.cherrypyserver import WebSocketPlugin, WebSocketTool
from ws4py.websocket import WebSocket

cherrypy.config.update({'server.socket_port': 80, 'server.socket_host': '0.0.0.0'})

WebSocketPlugin(cherrypy.engine).subscribe()
cherrypy.tools.websocket = WebSocketTool()

def make_error():
	this_makes_an_error()

class EchoWebSocket(WebSocket):
	def closed(self, code, reason=None):
		print 'socket closed'
	def received_message(self, msg):
                make_error()
		self.send(msg.data, msg.is_binary) # echo

class Root(object):
	@cherrypy.expose
	def index(self):
		return 'some HTML with a websocket javascript connection'

	@cherrypy.expose
	def ws(self):
		# you can access the class instance through
		handler = cherrypy.request.ws_handler

if __name__ == '__main__':
	cherrypy.quickstart(Root(), '/', config={'/ws': {'tools.websocket.on': True, 'tools.websocket.handler_cls': EchoWebSocket}})```


When I send a message into the socket via JavaScript, I see no error in the console, just a "socket closed."
Thanks for your help!

RobbieGM avatar Nov 06 '17 22:11 RobbieGM