Skip to content

Running into TLS1.3 packet chunk size issues with std.http #15626

@SuperAuguste

Description

@SuperAuguste

Zig Version

0.11.0-dev.2868+1a455b2dd

Steps to Reproduce and Observed Behavior

Make a POST request with a body of size greater than ~16383 - this'll cause a TlsAlert error.

Example:

const std = @import("std");

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

    var http_client: std.http.Client = .{ .allocator = allocator };

    var h = std.http.Headers{ .allocator = allocator };
    try h.append("Content-Type", "application/x-protobuf");

    const telemetry_uri = std.Uri.parse("https://telemetry.zigtools.org:4318/v1/traces") catch @panic("Invalid telemetry URI");

    var http_req = try http_client.request(.POST, telemetry_uri, h, .{});

    http_req.transfer_encoding = .chunked;

    var bruh = try allocator.alloc(u8, 17000);
    std.mem.set(u8, bruh, 'a');

    try http_req.start();
    try http_req.writeAll(bruh);
    try http_req.finish();
    try http_req.wait();
}

You'll get the following error:

C:\Programming\Zig\zig-from-the-website\lib\std\crypto\tls\Client.zig:1117:25: 0x7ff7c86d155a in readvAdvanced__anon_11015 (http.exe.obj)
                        return error.TlsAlert;
                        ^
C:\Programming\Zig\zig-from-the-website\lib\std\crypto\tls\Client.zig:898:19: 0x7ff7c86cba26 in readvAtLeast__anon_11014 (http.exe.obj)       
        var amt = try c.readvAdvanced(stream, iovecs[vec_i..]);
                  ^
C:\Programming\Zig\zig-from-the-website\lib\std\crypto\tls\Client.zig:859:5: 0x7ff7c86cb84c in readAtLeast__anon_11012 (http.exe.obj)
    return readvAtLeast(c, stream, &iovecs, len);
    ^
C:\Programming\Zig\zig-from-the-website\lib\std\crypto\tls\Client.zig:864:5: 0x7ff7c86cb7b1 in read__anon_11011 (http.exe.obj)
    return readAtLeast(c, stream, buffer, 1);
    ^
C:\Programming\Zig\zig-from-the-website\lib\std\http\Client.zig:176:31: 0x7ff7c869f6ea in read (http.exe.obj)
            error.TlsAlert => return error.TlsAlert,
                              ^
C:\Programming\Zig\zig-from-the-website\lib\std\http\Client.zig:264:23: 0x7ff7c8668b91 in fill (http.exe.obj)
        const nread = try bconn.conn.read(bconn.buf[0..]);
                      ^
C:\Programming\Zig\zig-from-the-website\lib\std\http\Client.zig:681:17: 0x7ff7c86642ab in wait (http.exe.obj)
                try req.connection.data.buffered.fill();
                ^
C:\Programming\Zig\sandbox\http.zig:27:5: 0x7ff7c8662912 in main (http.exe.obj)
    try http_req.wait();

Expected Behavior

The TLS client should split the request into properly sized chunks for me. @truemedian was mentioning adding in buffering to the std.http parts of the library, maybe that change could improve this too! :)

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions