tornadoweb / tornadoweb/tornado
WebSocket with regex route doesn't call open callback
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Description
I binded a tornado.websocket.WebSocketHandler with a normal route like "/ws" and it works as expected. However when i bind the handler with a regex route like "/nws/(.*)" it doesn't call the "open" callback.
Follows the shortest example i could build to show the issue:
import os
import tornado
import tornado.web
import tornado.gen
import tornado.websocket
class SocketHandler(tornado.websocket.WebSocketHandler):
def initialize(self):
print 'initialized'
def check_origin(self, origin):
return True
@tornado.gen.coroutine
def open(self):
print 'opened'
raise tornado.gen.Return()
@tornado.gen.coroutine
def on_message(self, message):
print 'on_message {}'.format(message)
self.write_message('resp: {}'.format(message))
@tornado.gen.coroutine
def on_close(self):
print 'closed'
application = tornado.web.Application([
(r"/ws", SocketHandler),
(r"/nws/(.*)", SocketHandler),
])
application.listen(8181)
print 'Server started on port: {}, pid: {}'.format(8181, os.getpid())
tornado.ioloop.IOLoop.instance().start()
So I run a normal client which fires the following operation:
- open
- send message "test"
- close
here the output when the path is /ws
initialized
opened
on_message test
closed
here the output when the path is /nws/abc
initialized
on_message test
closed
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided minimal example with both /ws and /nws/abc, then inspect tornado.web.Application route handling and the tornado.websocket.WebSocketHandler.open lifecycle. Done means the open callback is invoked for the regex route while the existing message and close behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100