aboutsummaryrefslogtreecommitdiff
path: root/src/http_client_async.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-03 21:01:14 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-02-03 21:01:14 -0800
commitbaffe26dd1e8da568fc77da53d36cd9c77d38c1d (patch)
tree827c6915b46f996673379c4be4d785d32942d16a /src/http_client_async.zig
parent1993f9f9a5f3b62ec55ee605d15dfce63afecbcd (diff)
downloadbun-baffe26dd1e8da568fc77da53d36cd9c77d38c1d.tar.gz
bun-baffe26dd1e8da568fc77da53d36cd9c77d38c1d.tar.zst
bun-baffe26dd1e8da568fc77da53d36cd9c77d38c1d.zip
Fix bug with http client
Diffstat (limited to 'src/http_client_async.zig')
-rw-r--r--src/http_client_async.zig9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/http_client_async.zig b/src/http_client_async.zig
index 171693ace..bd5c43d2d 100644
--- a/src/http_client_async.zig
+++ b/src/http_client_async.zig
@@ -47,6 +47,7 @@ pub fn onThreadStart() void {
AsyncIO.global_loaded = true;
NetworkThread.global.pool.io = &AsyncIO.global;
Global.setThreadName("HTTP");
+ AsyncBIO.initBoringSSL();
}
pub inline fn getAllocator() std.mem.Allocator {
@@ -412,15 +413,14 @@ pub const AsyncHTTP = struct {
this.state.store(.sending, .Monotonic);
var timer = std.time.Timer.start() catch @panic("Timer failure");
defer this.elapsed = timer.read();
- _ = active_requests_count.fetchAdd(1, .Monotonic);
this.response = await this.client.sendAsync(this.request_body.list.items, this.response_buffer) catch |err| {
- _ = active_requests_count.fetchSub(1, .Monotonic);
this.state.store(.fail, .Monotonic);
this.err = err;
if (sender.http.max_retry_count > sender.http.retries_count) {
sender.http.retries_count += 1;
+ sender.http.response_buffer.reset();
NetworkThread.global.pool.schedule(ThreadPool.Batch.from(&sender.task));
return;
}
@@ -430,7 +430,6 @@ pub const AsyncHTTP = struct {
this.redirect_count = @intCast(u32, @maximum(127 - this.client.remaining_redirect_count, 0));
this.state.store(.success, .Monotonic);
this.gzip_elapsed = this.client.gzip_elapsed;
- _ = active_requests_count.fetchSub(1, .Monotonic);
}
if (sender.http.callback) |callback| {
@@ -566,6 +565,10 @@ pub fn send(this: *HTTPClient, body: []const u8, body_out_str: *MutableString) !
// this prevents stack overflow
redirect: while (this.remaining_redirect_count >= -1) {
if (@enumToInt(this.stage) > @enumToInt(Stage.pending)) this.socket.deinit();
+ _ = AsyncHTTP.active_requests_count.fetchAdd(1, .Monotonic);
+ defer {
+ _ = AsyncHTTP.active_requests_count.fetchSub(1, .Monotonic);
+ }
this.stage = Stage.pending;
body_out_str.reset();