Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious traceback with enum switch #18574

Closed
melonedo opened this issue Jan 15, 2024 · 6 comments
Closed

Spurious traceback with enum switch #18574

melonedo opened this issue Jan 15, 2024 · 6 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@melonedo
Copy link
Contributor

melonedo commented Jan 15, 2024

Zig Version

0.12.0-dev.2236+32e88251e

Steps to Reproduce and Observed Behavior

The MWE deterministicaly triggers a TLS handshake failure, which is expected, but the trace back has unnecessary entries.

const std = @import("std");

pub fn main() !void {
    var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
    defer arena.deinit();
    const allocator = arena.allocator();

    var client = std.http.Client{ .allocator = allocator };
    defer client.deinit();
    try client.loadDefaultProxies();

    const url = "https://bing.com";

    const uri = try std.Uri.parse(url);
    var headers = std.http.Headers{ .allocator = allocator };
    defer headers.deinit();

    var req = try client.open(.GET, uri, headers, .{ .max_redirects = 10 });
    defer req.deinit();

    try req.send(.{});
    try req.wait();
    const body = try req.reader().readAllAlloc(allocator, 16 * 1024 * 1024);
    defer allocator.free(body);

    std.debug.print("{s}: {s}\n", .{ url, body });
}

When run with zig run traceback-issue.zig, the log is:

error: TlsInitializationFailed
/home/mlinux/Code/install/lib/zig/std/crypto/Certificate.zig:689:40: 0x12fcbb9 in parseEnum__anon_56046 (traceback-issue)
    return E.map.get(oid_bytes) orelse return error.CertificateHasUnrecognizedObjectId;
                                       ^
/home/mlinux/Code/install/lib/zig/std/crypto/Certificate.zig:680:5: 0x1271dab in parseExtensionId (traceback-issue)
    return parseEnum(ExtensionId, bytes, element);
    ^
/home/mlinux/Code/install/lib/zig/std/os.zig:766:27: 0x11146ce in read (traceback-issue)
            .CONNRESET => return error.ConnectionResetByPeer,
                          ^ 
------- Above is the true cause of error if you step through it -------
...[snip]...
/home/mlinux/Code/zig/traceback-issue.zig:18:15: 0x10a09f4 in main (traceback-issue)
    var req = try client.open(.GET, uri, headers, .{ .max_redirects = 10 });
              ^

Note that the code already errors upon reaching .CONNRESET => return error.ConnectionResetByPeer, but the top two trace back entries report spurious problem with parseEnum, which is unexpected.

Expected Behavior

The top two entries should not appear, i.e., the trace back starts from the line .CONNRESET => return error.ConnectionResetByPeer.

@melonedo melonedo added the bug Observed behavior contradicts documented or intended behavior label Jan 15, 2024
@melonedo
Copy link
Contributor Author

melonedo commented Jan 16, 2024

Bisection shows last good commit is b784f64, which is part of #18173. Commits in between can't compile until 67d7d7b introduced a fix, so they are all skipped.

Bisection script:

time cmake --build build --config Debug -t install -j || exit 125
time zig build-exe traceback-issue.zig || exit 125
! ./traceback-issue 2>&1 | grep 'return parseEnum(ExtensionId, bytes, element);'

Bisection log:

git bisect start
# bad: [32e88251e48d9f4a412b08acbd04d5694ec91e19] update test case for new const/var compile error
git bisect bad 32e88251e48d9f4a412b08acbd04d5694ec91e19
# good: [363d0ee5e13f4ac3a93d246121edfd00ef9fd97b] std.http: rename start->send and request->open to be more inline with operation
git bisect good 363d0ee5e13f4ac3a93d246121edfd00ef9fd97b
# good: [255737ea572f437afb1f2ad67096d3a157d79d70] spirv: fix memory leak in SpvModule
git bisect good 255737ea572f437afb1f2ad67096d3a157d79d70
# good: [372b407740224ae20fad49647bbde56330b24967] move eh_frame_hdr from link.File to Compilation
git bisect good 372b407740224ae20fad49647bbde56330b24967
# skip: [6bf319ebbb0bce945e9598a03783bc5a26f70e15] sema: extract runtime switch AIR generation to function
git bisect skip 6bf319ebbb0bce945e9598a03783bc5a26f70e15
# good: [3cd646869b1791b8833134294d3f415cb6fddcf7] Add tests for `--undefined-version`
git bisect good 3cd646869b1791b8833134294d3f415cb6fddcf7
# bad: [2ed9a276a701cc55eccf4fcbf68476e797f1818b] tar: use Go test cases path from env variable
git bisect bad 2ed9a276a701cc55eccf4fcbf68476e797f1818b
# bad: [3051d4390b0db3ed6669e8d17fb45edc26ff6fbd] Compilation: fix tsan error reporting
git bisect bad 3051d4390b0db3ed6669e8d17fb45edc26ff6fbd
# bad: [67d7d7b5a79cd709749f7435e1c3e4ef2e9150be] fixup! astgen: use switch_block_err_union
git bisect bad 67d7d7b5a79cd709749f7435e1c3e4ef2e9150be
# skip: [2fa69cce7261d223cbbc4b824a4da3ef41805214] sema: allow maybeErrorUnwrap to handle err_union_code
git bisect skip 2fa69cce7261d223cbbc4b824a4da3ef41805214
# skip: [a175a6438400d3e8842b4a4ac6a8cb76f53976a0] sema: implement runtime switch_block_err_union
git bisect skip a175a6438400d3e8842b4a4ac6a8cb76f53976a0
# good: [b784f64a6e4495f65d684e0afb00c4f7a62b950c] sema: refactor error set switch logic
git bisect good b784f64a6e4495f65d684e0afb00c4f7a62b950c
# skip: [adcaad6d91c309fab20ea208231c3e7d33fcc21f] sema: fix err union switch with inferred empty error sets
git bisect skip adcaad6d91c309fab20ea208231c3e7d33fcc21f
# skip: [fc6dc797ceff35c5bbaa51d914a62256bab3c409] astgen/sema: fix source locations for switch_block_err_union
git bisect skip fc6dc797ceff35c5bbaa51d914a62256bab3c409
# skip: [b7eb59fc140f3263b608a80fbe4e1ab56e04b318] fix x86_64 crashes for switch_block_err_union
git bisect skip b7eb59fc140f3263b608a80fbe4e1ab56e04b318
# skip: [ae19f699ab3a831d48a18c75d062fff17ab9268e] sema: implement switch_block_err_union on comptime operands
git bisect skip ae19f699ab3a831d48a18c75d062fff17ab9268e
# skip: [6a18cee3af8021bcebbca40413056b18f33af8c7] astgen/sema: use switch_block_err_union for if-else-switch
git bisect skip 6a18cee3af8021bcebbca40413056b18f33af8c7
# skip: [69ab687156f1099570ec2208efae8be6883073c0] test: add tests for switch_block_err_union
git bisect skip 69ab687156f1099570ec2208efae8be6883073c0
# skip: [8695bc7ed3583bb6b896079dd0b7bfd678e82722] langref: mention error union switch peer resolution
git bisect skip 8695bc7ed3583bb6b896079dd0b7bfd678e82722
# skip: [2cf648fba7f00bb42df1c8dad213a23427d528da] astgen: use switch_block_err_union
git bisect skip 2cf648fba7f00bb42df1c8dad213a23427d528da
# skip: [ec5b7513734fc7a6f7767dd721de8f6fa088b06d] sema: inherit block want_safety for err switch union
git bisect skip ec5b7513734fc7a6f7767dd721de8f6fa088b06d
# only skipped commits left to test
# possible first bad commit: [67d7d7b5a79cd709749f7435e1c3e4ef2e9150be] fixup! astgen: use switch_block_err_union
# possible first bad commit: [ec5b7513734fc7a6f7767dd721de8f6fa088b06d] sema: inherit block want_safety for err switch union
# possible first bad commit: [69ab687156f1099570ec2208efae8be6883073c0] test: add tests for switch_block_err_union
# possible first bad commit: [fc6dc797ceff35c5bbaa51d914a62256bab3c409] astgen/sema: fix source locations for switch_block_err_union
# possible first bad commit: [8695bc7ed3583bb6b896079dd0b7bfd678e82722] langref: mention error union switch peer resolution
# possible first bad commit: [6a18cee3af8021bcebbca40413056b18f33af8c7] astgen/sema: use switch_block_err_union for if-else-switch
# possible first bad commit: [b7eb59fc140f3263b608a80fbe4e1ab56e04b318] fix x86_64 crashes for switch_block_err_union
# possible first bad commit: [adcaad6d91c309fab20ea208231c3e7d33fcc21f] sema: fix err union switch with inferred empty error sets
# possible first bad commit: [2fa69cce7261d223cbbc4b824a4da3ef41805214] sema: allow maybeErrorUnwrap to handle err_union_code
# possible first bad commit: [a175a6438400d3e8842b4a4ac6a8cb76f53976a0] sema: implement runtime switch_block_err_union
# possible first bad commit: [6bf319ebbb0bce945e9598a03783bc5a26f70e15] sema: extract runtime switch AIR generation to function
# possible first bad commit: [ae19f699ab3a831d48a18c75d062fff17ab9268e] sema: implement switch_block_err_union on comptime operands
# possible first bad commit: [2cf648fba7f00bb42df1c8dad213a23427d528da] astgen: use switch_block_err_union

@melonedo melonedo changed the title Spurious traceback with TLS handshake failure Spurious traceback with enum switch Jan 16, 2024
@melonedo
Copy link
Contributor Author

melonedo commented Jan 18, 2024 via email

@tau-dev
Copy link
Contributor

tau-dev commented Jan 18, 2024

Thank you!

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Jan 18, 2024
@melonedo
Copy link
Contributor Author

@Vexu why is this not planned? Does it mean we should interpret all failures of TLS as Certificate errors?

@nektro
Copy link
Contributor

nektro commented Jan 20, 2024

because its a duplicate of the issue mentioned above

@melonedo
Copy link
Contributor Author

melonedo commented Jan 20, 2024

Thanks! I didn't see it.
Edit: I mean that issue is just one way to trigger the bug, the bug is that the return trace is misleading. I can still reproduce it after #18599.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

4 participants