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.

BrokenResourceError

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

app.py

import time
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware


app = FastAPI()


@app.middleware("http")
async def middleware(request: Request, call_next):
    return await call_next(request)


@app.get("/")
def read_root():
    time.sleep(4)
    return {"Hello": "World"}


if __name__ == "__main__":
    uvicorn.run(app="app:app", port=8000)

script.py

import requests as requests

r = requests.get(f"http://127.0.0.1:8000", timeout=2)

Description

If you trigger script.py, error will appear. After upgrade fastapi to 0.70.0 In some requests in our application its apearing this error. So what we can do? What is problem?

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "venv/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 398, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "venv/lib/python3.8/site-packages/fastapi/applications.py", line 208, in __call__
    await super().__call__(scope, receive, send)
  File "venv/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc
  File "venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "venv/lib/python3.8/site-packages/starlette/middleware/base.py", line 57, in __call__
    task_group.cancel_scope.cancel()
  File "venv/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 567, in __aexit__
    raise exceptions[0]
  File "venv/lib/python3.8/site-packages/starlette/middleware/base.py", line 30, in coro
    await self.app(scope, request.receive, send_stream.send)
  File "venv/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc
  File "venv/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "venv/lib/python3.8/site-packages/starlette/routing.py", line 656, in __call__
    await route.handle(scope, receive, send)
  File "venv/lib/python3.8/site-packages/starlette/routing.py", line 259, in handle
    await self.app(scope, receive, send)
  File "venv/lib/python3.8/site-packages/starlette/routing.py", line 64, in app
    await response(scope, receive, send)
  File "venv/lib/python3.8/site-packages/starlette/responses.py", line 139, in __call__
    await send({"type": "http.response.body", "body": self.body})
  File "venv/lib/python3.8/site-packages/starlette/exceptions.py", line 68, in sender
    await send(message)
  File "venv/lib/python3.8/site-packages/anyio/streams/memory.py", line 205, in send
    raise BrokenResourceError
anyio.BrokenResourceError

Operating System

Linux

Operating System Details

No response

FastAPI Version

0.70.0

Python Version

3.8

Additional Context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:14
  • Comments:43 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
havardthomcommented, Nov 4, 2021

This is fixed in Starlette v0.17.0, hopefully FastAPI bumps starlette again on next release

11reactions
jangiacommented, Feb 1, 2022

Still experiencing this issue:

  • fastapi == 0.72.0
  • starlette == 0.17.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

API reference — AnyIO 3.6.2 documentation - Read the Docs
EndOfStream – if this stream has been closed from the other end. BrokenResourceError – if this stream has been rendered unusable due to...
Read more >
Python trio.BrokenResourceError() Examples
This page shows Python examples of trio.BrokenResourceError.
Read more >
Right way to terminate a trio program without ... - Stack Overflow
The traceback says that the BrokenResourceError is coming from a call to await send_channel.send(...) . send_channel.send raises this error ...
Read more >
Understanding the "Broken Resource" Error - ZAP Data Hub
The resource you are accessing was created in a later version of Data Hub than the one you are using. The resource has...
Read more >
Airbyte - Error] ssl.SSLSyscallError: Some I/O error occurred ...
BrokenResourceError During handling of the above exception, another exception occurred: Traceback (most recent call last): File ...
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