Skip to content

Can't fetch tag.gz package on linux #25887

@travisstaloch

Description

@travisstaloch

Zig Version

0.16.0-dev.1276+c58687225

Steps to Reproduce and Observed Behavior

I noticed my flatbuferz lib segfaulting since around 0.16.0-dev.1225 when Io.Threaded was introduced when running zig build. You should be able to reproduce a segfault (or similar stack trace with a debug compiler build) by running

git clone git@github.com:travisstaloch/flatbufferz.git
cd flatbufferz
zig build

The issue seems to happen while downloading the dep file https://github.com/google/flatbuffers/archive/refs/tags/v24.3.25.tar.gz

Maybe related to #25776. The following reproduction is a copy of @squeek502's repro here #25776 (comment) but with my dep file path.

// /tmp/tmp.zig
const std = @import("std");

pub fn main() !void {
    var debug_allocator: std.heap.DebugAllocator(.{}) = .{};
    defer std.debug.assert(debug_allocator.deinit() == .ok);
    const gpa = debug_allocator.allocator();

    var threaded: std.Io.Threaded = .init(gpa);
    defer threaded.deinit();
    const io = threaded.io();

    var client: std.http.Client = .{ .io = io, .allocator = gpa };
    defer client.deinit();

    var body: std.Io.Writer.Allocating = .init(gpa);
    defer body.deinit();

    const res = try client.fetch(.{
        .location = .{ .url = "https://github.com/google/flatbuffers/archive/refs/tags/v24.3.25.tar.gz" },
        .method = .GET,
        .response_writer = &body.writer,
    });

    std.debug.print("{}\n", .{res.status});
    std.debug.print("{s}\n", .{body.written()});
}
$ zig version
0.16.0-dev.1262+be4eaed7c
$ zig run /tmp/tmp.zig
thread 3796124 panic: reached unreachable code
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/debug.zig:416:14: 0x10575c9 in assert (std.zig)
    if (!ok) unreachable; // assertion failure
             ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Reader.zig:521:11: 0x10d21f8 in toss (std.zig)
    assert(r.seek <= r.end);
          ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:5538:20: 0x119c946 in lookupHostsReader (std.zig)
        reader.toss(1);
                   ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:5502:29: 0x118d4ba in lookupHosts (std.zig)
    return lookupHostsReader(t, host_name, resolved, options, &file_reader.interface) catch |err| switch (err) {
                            ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:4841:20: 0x118de8a in netLookupFallible (std.zig)
        lookupHosts(t, host_name, resolved, options) catch |err| switch (err) {
                   ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:4703:66: 0x118ebec in netLookup (std.zig)
    resolved.putOneUncancelable(t_io, .{ .end = netLookupFallible(t, host_name, resolved, options) });
                                                                 ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/net/HostName.zig:98:31: 0x151f1c2 in lookup (std.zig)
    return io.vtable.netLookup(io.userdata, host_name, resolved, options);
                              ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io.zig:1034:17: 0x14bfceb in start (std.zig)
                @call(.auto, function, args_casted.*);
                ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:605:16: 0x109687a in start (std.zig)
        gc.func(group, gc.contextPointer());
               ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Io/Threaded.zig:188:26: 0x1100646 in worker (std.zig)
            closure.start(closure);
                         ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Thread.zig:558:13: 0x10d9ed0 in callFn__anon_16095 (std.zig)
            @call(.auto, f, args);
            ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/Thread.zig:1534:30: 0x10b66c0 in entryFn (std.zig)
                return callFn(f, self.fn_args);
                             ^
~/.local/share/zigup/0.16.0-dev.1262+be4eaed7c/files/lib/std/os/linux/x86_64.zig:105:5: 0x10d9f85 in clone (std.zig)
    asm volatile (
    ^
Aborted (core dumped)

Expected Behavior

I think the flatbufferz lib should build and the reproduction should also work. The flatbufferz lib built fine in 0.15 and in 0.16-dev versions prior to the introduction of Io.Threaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions