Skip to content

std.http.Client blocks forever with larger payloads on HTTPS requests #25015

@Cloudef

Description

@Cloudef

Zig Version

0.16.0-dev.27+83f773fc6

Steps to Reproduce and Observed Behavior

Large payloads for std.http.Client.fetch seem to block forever under HTTPS connections. Increasing write_buffer_size in http.Client workarounds it.

How to reproduce:

const std = @import("std");

const Client = std.http.Client;

pub fn main() !void {
    const alloc = std.heap.page_allocator;

    var allocating = std.Io.Writer.Allocating.init(alloc);
    defer allocating.deinit();

    const opts: Client.FetchOptions = .{
        .method = .POST,
        .location = .{ .url = "https://httpbin.org/post" },
        .payload = "631df10a8621493a1f71ce5e068583395846480e0f127f1c9ab46f6cbad83829" ** 64,
        .response_writer = &allocating.writer,
    };

    var client: Client = .{ .allocator = alloc };
    defer client.deinit();

    _ = try client.fetch(opts);

    std.debug.print("{s}\n", .{allocating.written()});
}

Workaround by increasing write_buffer_size:

const std = @import("std");

const Client = std.http.Client;

pub fn main() !void {
    const alloc = std.heap.page_allocator;

    var allocating = std.Io.Writer.Allocating.init(alloc);
    defer allocating.deinit();

    const opts: Client.FetchOptions = .{
        .method = .POST,
        .location = .{ .url = "https://httpbin.org/post" },
        .payload = "631df10a8621493a1f71ce5e068583395846480e0f127f1c9ab46f6cbad83829" ** 64,
        .response_writer = &allocating.writer,
    };

    var client: Client = .{ .allocator = alloc, .write_buffer_size = 8192 };
    defer client.deinit();

    _ = try client.fetch(opts);

    std.debug.print("{s}\n", .{allocating.written()});
}

Changing url to http:// instead of https:// works as well.

Expected Behavior

The post request gets sent without blocking forever and without requiring increasing the write_buffer_size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions