File tree 2 files changed +27
-4
lines changed 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,15 @@ pub const ConnectionPool = struct {
92
92
93
93
if (node .data .closing ) {
94
94
node .data .deinit (client );
95
-
96
95
return client .allocator .destroy (node );
97
96
}
98
97
99
- if (pool .free_len + 1 >= pool .free_size ) {
98
+ if (pool .free_len >= pool .free_size ) {
100
99
const popped = pool .free .popFirst () orelse unreachable ;
100
+ pool .free_len -= 1 ;
101
101
102
102
popped .data .deinit (client );
103
-
104
- return client .allocator .destroy (popped );
103
+ client .allocator .destroy (popped );
105
104
}
106
105
107
106
if (node .data .proxied ) {
Original file line number Diff line number Diff line change @@ -571,6 +571,30 @@ pub fn main() !void {
571
571
// connection has been kept alive
572
572
try testing .expect (client .connection_pool .free_len == 1 );
573
573
574
+ { // issue 16282
575
+ const location = try std .fmt .allocPrint (calloc , "http://127.0.0.1:{d}/get" , .{port });
576
+ defer calloc .free (location );
577
+ const uri = try std .Uri .parse (location );
578
+
579
+ const total_connections = client .connection_pool .free_size + 64 ;
580
+ var requests = try calloc .alloc (http .Client .Request , total_connections );
581
+ defer calloc .free (requests );
582
+
583
+ for (0.. total_connections ) | i | {
584
+ var req = try client .request (.GET , uri , .{ .allocator = calloc }, .{});
585
+ req .response .parser .done = true ;
586
+ req .connection .? .data .closing = false ;
587
+ requests [i ] = req ;
588
+ }
589
+
590
+ for (0.. total_connections ) | i | {
591
+ requests [i ].deinit ();
592
+ }
593
+
594
+ // free connections should be full now
595
+ try testing .expect (client .connection_pool .free_len == client .connection_pool .free_size );
596
+ }
597
+
574
598
client .deinit ();
575
599
576
600
killServer (server .socket .listen_address );
You can’t perform that action at this time.
0 commit comments