ashleysommer / sanic-cors

A Sanic extension for handling Cross Origin Resource Sharing (CORS), making cross-origin AJAX possible. Based on flask-cors by Cory Dolphin.
MIT License
159 stars 22 forks source link

<Request: OPTIONS /some/route> body not consumed. #52

Open digitalkaoz opened 3 years ago

digitalkaoz commented 3 years ago

Hey,

im bending my mind around a weird problem. it only happens occasionally and i cant find the root cause:

app = Sanic(__name__)
CORS(app, resources={r"/*": {"origins": "*"}})

@app.route('/some/route', methods=['GET'])
async def some_route_handler(request: Request) -> HTTPResponse:
    return empty()

when accessing this from a client-side app using axios:

    const response = await axios.get(`some/route`, {
      params: { ...filters } // query params
    });

i sometimes get this error:

{
    "timestamp": "2021-09-02T13:04:39.351303Z",
    "level": "ERROR",
    "message": "<Request: OPTIONS /some/route> body not consumed.",
    "type": "log",
    "logger": "sanic.error",
    "worker": 9,
    "filename": "http.py",
    "lineno": 154,
    "req_id": "28844799-4fe1-4ba1-a5c6-b0933142d709"
}

i literally have no idea whats wrong.

automatic_options=True should be enabled by default afaik. There is also JWT included but i guess thats not the problem. Any ideas?

Im definitely not sending a Request Body during the preflight request. Everything seems to work, but this problem is spamming my logging system.

ZSSVE commented 2 years ago

I saw a similar issue. With automatic_options=True, it looks like that sanic-cors would directly return an empty response around here, while since Sanic 21.3.0 (this commit), setting response without reading the body would trigger an error logging.

I am unclear if our Options requests have body.

fkromer commented 1 year ago

With sanic==21.12.1 and Sanic-Cors==2.0.1 this issue still exists. I've not come further here unfortunately yet.

fkromer commented 1 year ago

During debugging seems like you can workaround this issue by setting sanic_workers=1. After re-configuring I had the issue not again yet.