Reflections by Efim
862 m
Auto-translated from Russian
Bug #2. The issue occurred in 2021. At the time, I was working on a project that used .NET on the backend and the PostgreSQL database. We used Entity Framework Core and Npgsql to interact with the database.

Sometimes, when using the application, a strange error would occur during database queries. The error message indicated an unexpected result after a specific step in the query. To better understand, let's imagine the query execution as a sequence of steps (1, 2, 3, ...). What happened was that after completing step 1, we received a response as if step 3 had been executed. In essence, something was interfering with the query execution process and corrupting its state.

The application code was thoroughly examined, but we couldn't find any race conditions. Furthermore, this error occurred relatively rarely – once every few hours under heavy load.

After several days of diligent debugging and hypothesis testing, we discovered that the frequency of the error was affected by the keepalive parameter – the automatic maintenance of the connection in an active state. As the keepalive value decreased, the error frequency increased. Based on this knowledge, I delved deeper into Npgsql and found that keepalive was not 100% reliable in terms of concurrency.

It turned out that this problem was not unique to us. I was able to find a corresponding bug on GitHub (you can read my correspondence with the developers). As a temporary solution, keepalive was disabled, and the bug was fixed in the next version of the library.

The moral of the story is that a race condition can come from where you least expect it 😄

How often do you encounter bugs in your dependencies?

#work #programming #bugs