HTTP Client's ConnectionPool erroneously leaks memory, then panics when releasing nodes at full capacity #16282
Labels
bug
Observed behavior contradicts documented or intended behavior
standard library
This issue involves writing Zig code for the standard library.
Milestone
Zig Version
0.11.0-dev.3892+0a6cd257b
Steps to Reproduce and Observed Behavior
When the HTTP client's ConnectionPool attempts to release a used connection into its pool of free connections, if the pool of free connections is already at capacity, the ConnectionPool will free one of the open connections it already contains, but then it will not add the previously used connection to its pool to compensate for this removal. This results in an orphaned node which has its memory leaked.
In addition, each time this occurs the ConnectionPools "free_len" value will not be decremented even though the actual length of the free pool has decreased. Eventually, this leads to a situation where the ConnectionPool's free_len value will tell it that it already has the maximum desired amount of free connections when in fact it has zero free connections. At this point it will attempt to remove a node from its now empty free pool at which point the program will panic.
Here is a minimal reproduction of the error with tests for the memory leak and the panic.
connection_error_repro.zip
Expected Behavior
Presumably repeatedly making and then deinitializing http requests should not be causing either memory leaks or panics due to hitting unreachable code.
The text was updated successfully, but these errors were encountered: