Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS/ASGI/AsyncServer RuntimeWarning: coroutine 'make_response' was never awaited #145

Closed
JoseRaffucci opened this issue Nov 2, 2019 · 1 comment
Assignees
Labels

Comments

@JoseRaffucci
Copy link

While I was testing socket.io integration with uvicorn I ran into an issue with CORS. When you do not supply the argument cors_allowed_origins the error RuntimeWarning: coroutine 'make_response' was never awaited occurs and the server returns 500 error. If you supply cors_allowed_origins=[] with an empty array, everything works but not as expected. The client from another domain makes the connection without being in the allowed origins list.

Server side code to produce the issue:

import uvicorn
import socketio

sio = socketio.AsyncServer(
    async_mode="asgi",
    # cors_allowed_origins=[],
    logger=True
)

@sio.event
async def connect(sid, environ):
    print(sid)

if __name__ == "__main__":
    sioapp = socketio.ASGIApp(sio)
    uvicorn.run(sioapp, host="127.0.0.1", port=6270, log_level="info")

Generated Error:

INFO:     Started server process [24304]
INFO:     Uvicorn running on http://127.0.0.1:6270 (Press CTRL+C to quit)
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     ('127.0.0.1', 61948) - "WebSocket /socket.io/" [accepted]
C:\Users\x\.virtualenvs\sio-test-SdSnYm_O\lib\site-packages\engineio\async_drivers\asgi.py:46: RuntimeWarning: coroutine 'make_response' was never awaited
  await self.engineio_server.handle_request(scope, receive, send)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
INFO:     ('127.0.0.1', 61970) - "WebSocket /socket.io/" [accepted]
INFO:     ('127.0.0.1', 61985) - "WebSocket /socket.io/" [accepted]
INFO:     Shutting down
INFO:     Waiting for application shutdown.
INFO:     Application shutdown complete.
INFO:     Finished server process [24304]

If you remove the comment from the code above anything is accepted, but if you provide 1 host in the list that does not match the request host you get the same error as above.

I am not sure if placing an await in front of make_response on line 203 of asyncio_server.py is the full solution as I got other errors with uvicorn. Please let me know if you need additional information on the issue.

My Environment:
Windows 10
Python: 3.8.0

@miguelgrinberg miguelgrinberg self-assigned this Nov 2, 2019
@miguelgrinberg
Copy link
Owner

Thanks, I'll take care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants