cd /news/developer-tools/segfault-when-reading-from-serversid… · home topics developer-tools article
[ARTICLE · art-130441] src=ziggit.dev ↗ pub= topic=developer-tools verified=true sentiment=↓ negative

Segfault when reading from serverside tcp connection

A Zig developer reports a segmentation fault at address 0x79 while reading from an accepted TCP connection using Zig 0.17.0-dev.1786+75044cb04, with the crash traced through std.Io.zig:554 in io.vtable.operate during a call to Reader.fillMore. The developer's first Zig project, a sensor-measurement collection server binding to ::1 port 1312, segfaults immediately after netcat connects and the code calls ri.fillMore(). The stack trace points to std/Io/net.zig:1275 in read and std/Io/Reader.zig:1138 in fillMore, and the developer is asking for help diagnosing the failure.

read2 min views3 publishedSep 15, 2026

heyo everyone, this one is coming to zig in hopes of having fun with computers and other beings, learning cool programming stuff, and being not (less) bothered by llms and ai bs.

This one did some ziglings exercises to get into the language and has now started on its first zig project, a collection server for sensor measurements. The sensors will most likely talk with the server using json inside http inside (mutual) tls.

For now this one’s goal is to bind to a socket, to accept connections and read from them. This one is running into issues trying to read from a connection:

const std = @import("std");
const Io = std.Io;
const dprint = std.debug.print;

pub fn main(init: std.process.Init) !void {
    // In order to do I/O operations need an `Io` instance.
    const io = init.io;

    const address = try std.Io.net.IpAddress.parse("::1", 1312);

    dprint("addr: {}\n", .{address});

    var listener = try address.listen(io, .{
        .reuse_address = true,
    });
    defer listener.deinit(io);

    var buffer: [1024]u8 = undefined;

    while (true) {
        const stream = try listener.accept(io);
        dprint("accepted connection from: {}\n", .{stream.socket.address});
        const reader = stream.reader(io, &buffer);
        var ri = reader.interface;

        if (ri.fillMore()) {
            dprint("possibly filled the buffer", .{});
        } else |err| {
            dprint("failed to fill the buffer because: {any}", .{err});
        }

        // if (ri.takeDelimiterInclusive('\n')) |line| {
        //     dprint("line: {s}", .{line});
        // } else |err| {
        //     dprint("error: {}", .{err});
        // }

        try stream.shutdown(io, .both);
    }
}

When run this code produces this output and segfaults when getting a connection (from netcat):

addr: .{ .ip6 = .{ .port = 1312, .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, .flow = 0, .interface = .{ .index = 0 } } }
accepted connection from: .{ .ip6 = .{ .port = 40616, .bytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, .flow = 0, .interface = .{ .index = 0 } } }
Segmentation fault at address 0x79
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/Io.zig:554:29: 0x103e393 in operate (std.zig)
    return io.vtable.operate(io.userdata, operation);
                            ^
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/Io/net.zig:1275:31: 0x11f3118 in read (std.zig)
        return (try io.operate(.{ .net_read = .{
                              ^
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/Io/net.zig:1329:36: 0x11f2b85 in readVec (std.zig)
            const n = r.stream.read(io, dest) catch |err| {
                                   ^
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/Io/Reader.zig:1138:29: 0x108422b in fillMore (std.zig)
    _ = try r.vtable.readVec(r, &bufs);
                            ^
/home/digital/projects/comfy-aggregator/src/main.zig:26:24: 0x11e532f in main (main.zig)
        if (ri.fillMore()) {
                       ^
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/start.zig:797:30: 0x11e5f98 in callMain (std.zig)
    return wrapMain(root.main(.{
                             ^
/home/digital/zig-x86_64-linux-0.17.0-dev.1786+75044cb04/lib/std/start.zig:218:5: 0x11e4ca1 in _start (std.zig)
    asm volatile (switch (native_arch) {
    ^
fish: Job 1, './zig-out/bin/comfy_aggregator …' terminated by signal SIGABRT (Abort)

This one is using zig 0.17.0-dev.1786+75044cb04 (because that’s what ziglings asked for).

Please help this one by teaching it how to find a solution for its problem or explain why this is failing.

── more in #developer-tools 4 stories · sorted by recency
── more on @zig 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/segfault-when-readin…] indexed:0 read:2min 2026-09-15 ·