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.

Double free error in tcache 2

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

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jgould22commented, Feb 16, 2022

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.

0reactions
jgould22commented, Feb 16, 2022

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

free(): double free detected in tcache 2 in C++ - Stack Overflow
Program output says there is double free situation but I cannot see the place where this error occurs. Code may be seen a...
Read more >
PSET5 compiles but gives: "free(): double free detected in ...
The error is triggered because the free() statement is attempting to free the same address, stored in different nodes. This means that there's...
Read more >
Getting "double free detected in tcache 2" in speller ... - Reddit
As I understand it, double free means that I'm trying to free memory locations that have been freed in the past and that...
Read more >
free(): double free detected in tcache 2 Aborted (core dumped)
I want to implement a program that reads data from a file specified as a command-line argument, having the following format:
Read more >
double free detected in tcache 2 - C++ Forum
I am facing extra memory freed errors, when I try to run it with Valgrind and getting the error "free(): double free detected...
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