sanic: Crash when sending simultaneous requests to long-running routes

The following code that runs blocking code in a thread pool causes Sanic to crash for me with a “Fatal Python error: Cannot recover from stack overflow error.” when sending 10 or so simultaneous requests to the server. Commenting out the line that sets the event loop policy to uvloop (the default) makes the situation a bit better, with occasional “Writing response failed, connection closed ‘NoneType’ object has no attribute ‘should_keep_alive’” errors but no crash. Thoughts?

from sanic import Sanic
from sanic.response import text
import asyncio
import uvloop
import time
from functools import partial
from concurrent.futures import ThreadPoolExecutor

asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
loop = asyncio.get_event_loop()
thread_pool = ThreadPoolExecutor(max_workers=20)

app = Sanic()

@app.route('/')
async def test(request):
	return text(await loop.run_in_executor(thread_pool, partial(time.sleep,5)))

app.run(host="0.0.0.0", port=8000, loop=loop, workers=1)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (15 by maintainers)

Commits related to this issue

Most upvoted comments

@jackfischer 0.3.0 should be released by the end of the week.