question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't exit cleanly with Sanic integration

See original GitHub issue

I’m adding socketio support to a Sanic app with

sio = socketio.AsyncServer(
    async_mode='sanic',
    cors_allowed_origins="*", # TODO only CORS in dev
    ping_interval=PING_INTERVAL,
)
sio.attach(app)

The app is started by a console script that calls app.run(host=bind_host, port=bind_port).

When I use Ctrl-C or systemctl restart appname, with websocket connections open, the app never exits and has to be repeatedly Ctrl-Ced or killed.

Buggy output

[2019-11-14 14:57:22 -0300] - (sanic.access)[INFO][127.0.0.1:64039]: GET http://127.0.0.1:8000/socket.io/?EIO=3&transport=polling&t=Mvh40Iv&sid=0c54f70a83fc45c6b3776b38b8601f31  200 4
INFO:sanic.access:
^C[2019-11-14 15:03:03 -0300] [9624] [INFO] Stopping worker [9624]
INFO:sanic.root:Stopping worker [9624]
[2019-11-14 15:03:08 -0300] [9624] [INFO] Server Stopped
INFO:sanic.root:Server Stopped
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending coro=<AsyncServer._service_task() running at /Users/jlong/miniconda3/lib/python3.7/site-packages/engineio/asyncio_server.py:452> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x1040808e8>()]>>

Output where no sockets were open

[2019-11-14 15:27:59 -0300] [9732] [INFO] Starting worker [9732]
INFO:sanic.root:Starting worker [9732]
INFO:purepyindi.eventful:Connected to ('::1', 7624, 0, 0)
^C[2019-11-14 15:28:02 -0300] [9732] [INFO] Stopping worker [9732]
INFO:sanic.root:Stopping worker [9732]
[2019-11-14 15:28:02 -0300] [9732] [INFO] Server Stopped
INFO:sanic.root:Server Stopped

Does python-socketio register its websocket tasks in the Sanic.websocket_tasks list? (https://github.com/miguelgrinberg/sanic/commit/fd823c63aba8b7a74da4660a7e1dfbf4c2a05ea3)

I’m having trouble following exactly how sio.attach operates, but since that Sanic commit is by the same author it seems likely it does—meaning there’s something else I’m missing. (Incidentally, thanks for your work! Impressive library.)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
joseph-longcommented, Jan 19, 2020

Update: I solved this, but my solution isn’t really a solution for Sanic. I migrated to Starlette, which seems to follow the consensus ASGI API, and by composing with socketio.ASGIApp I got the clean shutdown behavior I wanted.

0reactions
miguelgrinbergcommented, Jan 19, 2020

Feel free to submit a PR if you have an improvement to propose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sanic Documentation
Sanic is a Python 3.6+ web server and web framework that's written to go fast. It allows the usage of the async/await.
Read more >
TortoiseGit-git did not exit cleanly (exit code 1) - Stack Overflow
Try these two commands in git bash: 1) git gc --force. 2) git fetch -p.
Read more >
Sonic Mania - PCGamingWiki PCGW
The game is made on a definition of 424x240. If you want to have a sharp and clean image, you need to multiply...
Read more >
3D Far-Field Sonic Service - SLB
Imaging integration from the wellbore to the far field. The 3D far-field sonic service integrates results from borehole imaging logs to trace features...
Read more >
SAMPLE PREPARATION FUNDAMENTALS FOR ... - Agilent
This inlet is primarily used for trace analysis in clean matrices such as ... for extraction or concentration of many analytes that cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found