Double free error in tcache 2
See original GitHub issueFirst 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
for (let i = 0; i < 2; i++) {
axios
.post(URL + '/data/fetch/salle', getContent())
.then(res => {
console.log(`statusCode: ${res.status}`)
// console.log(res)
})
.catch(error => {
// console.error(error)
console.error("Error")
})
}
Description
Hi, I wanted to do a stress test on my api and make a lot of request to see if it can handle it. I precise my API run in a docker container with a flask website (with nginx) and a database (mysql) each request call the database to execute a select.
The problem is that my api is working well but when I do plenty of simultaneous request it crash with the error double free or either, free(): error in tcache 2. Can someone help me please ?
secondtour-api | INFO: 192.168.224.1:45528 - “POST /data/fetch/salle HTTP/1.1” 200 OK secondtour-api | INFO: 192.168.224.1:45530 - “POST /data/fetch/salle HTTP/1.1” 200 OK secondtour-api | INFO: 192.168.224.1:45532 - “POST /data/fetch/salle HTTP/1.1” 200 OK secondtour-api | double free or corruption (fasttop) secondtour-api exited with code 139
Operating System
Linux, Windows
Operating System Details
I’m on windows and the api run in a linux container
FastAPI Version
0.73.0
Python Version
Python 3.9.5
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top GitHub Comments
Without seeing server side code it is very difficult to help you.
To better help you need to provide us with at least a small FastAPI code sample that produces the issue.
Additionally since
requests
is a sync lib I think your python code is only going to send one request at a time which is why you might not see the behavior with that python snippet.Right, it seems likely that you cannot share that db connection between tasks or threads as it might not thread safe.
I would first try moving your db connection into your
read_root
function and then see if that causes the issue.This will be slower(since it is initializing a new db connection for each request) but if you don’t get there error anymore you know that will be the issue.
Then you will need to refactor your application so it is not sharing that db (and probably change the MySQL library you are using to something that is async, perhaps aiomysql).