Skip to content

Zig build causes segfault when package manager depends on .url from github with https #15723

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

Open
edyu opened this issue May 15, 2023 · 20 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@edyu
Copy link
Contributor

edyu commented May 15, 2023

Zig Version

0.11.0-dev.3879+5804f3f75

Steps to Reproduce and Observed Behavior

This is more of informational than exact step. I don't know enough of the internals to pinpoint where the error originated from but maybe someone who does can see what would cause this problem.
I have 2 laptops (one has intel and the other has amd). Both run windows 11 and I use both with Ubuntu 22.04 LTS WSL2.
On one of them when I call zig build on for example the zigzap/zap repository, it would cause the following error:
signal SIGSEGV (Address boundary error)
However, after I installed gdb with sudo apt install gdb the problem went away. SEE BELOW

EDIT: It didn't go away as I now realized that once I download it once (using a workaround of localhost serving the package with http not https) and it gets cached.

EDIT2: The package IS available at the url as I can download the package manually.

Expected Behavior

Should compile ok without installing gdb first.

@edyu edyu added the bug Observed behavior contradicts documented or intended behavior label May 15, 2023
@edyu
Copy link
Contributor Author

edyu commented May 16, 2023

Maybe it's caused by the new package manager and when .url in the .dependencies for a package is unavailable, it would cause this problem.
'zig build' terminated by signal SIGSEGV (Address boundary error)

@edyu edyu changed the title Zig build causes segfault on AMD-based WSL2 Zig build causes segfault when .url of a package is not available May 16, 2023
@DraagrenKirneh
Copy link
Contributor

@edyu are you invoking zig build on package located in a windows folder or a subsystem folder?

@edyu
Copy link
Contributor Author

edyu commented May 16, 2023

@edyu are you invoking zig build on package located in a windows folder or a subsystem folder?

On subsystem folder.

@edyu
Copy link
Contributor Author

edyu commented May 16, 2023

Here is the config that would've have caused it.

.{
    .name = "My example project",
    .version = "0.0.1",

    .dependencies = .{
        // zap release-0.0.20
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/release-0.0.20.tar.gz",
            .hash = "12200772b594bc50bbdc18b14aa3c7461991a33179f9c254de05eb34d214662971da",
        }
    }
}

@DraagrenKirneh
Copy link
Contributor

DraagrenKirneh commented May 16, 2023

Can confirm that this is happening on WSL, when gdb is not present.

zig init-exe
touch build.zig.zon
# copy the content from the comment above
zig build
# Segmentation fault (core dumped)

Builds as expected if I remove the zon file.

@nektro
Copy link
Contributor

nektro commented May 16, 2023

on linux that yields the following, though it is also weird how there's an extra line between the caret and the message

/home/meghan/src/temp/build.zig.zon:1:1: error: expected expression, found 'EOF'

^

@edyu
Copy link
Contributor Author

edyu commented May 19, 2023

As of zig version 0.11.0-dev.3206+b9d2e0e30, I'm not seeing this problem anymore. Maybe it's related to the TLS fix.

@edyu
Copy link
Contributor Author

edyu commented May 24, 2023

Now the error is error: TlsFailure
version is now error: 0.11.0-dev.3286+dcc1b4fd1

@edyu
Copy link
Contributor Author

edyu commented May 24, 2023

And sometimes error: BadReaderState

@edyu
Copy link
Contributor Author

edyu commented May 28, 2023

Still having the following error at 0.11.0-dev.3312+ab37ab33c
'zig build' terminated by signal SIGSEGV (Address boundary error)

.{
    .name = "mytest",
    .version = "0.0.2",

    .dependencies = .{
        // zap v0.1.4-pre
        .zap = .{
            .url = "https://github.com/zigzap/zap/archive/refs/tags/v0.1.4-pre.tar.gz",
            .hash = "12204613bae513282f2b7e468045401cbae09bb19e42baeca193b9c98ff6f2ceb6ef",
        }
    }
}

@edyu
Copy link
Contributor Author

edyu commented May 28, 2023

And I can confirm that if i replace the url with a localhost serving the tar.gz such as python and I change the .url to http://localhost:8000/v0.1.4-pre.tar.gz, the zig build would work. So it's most likely something screwy in the package fetching code.

@edyu
Copy link
Contributor Author

edyu commented May 28, 2023

btw, I'm running Ubuntu 22.04 LTS in WSL2 on an AMD 5800HS (not sure how relevant).

@edyu edyu changed the title Zig build causes segfault when .url of a package is not available Zig build causes segfault May 28, 2023
@edyu edyu changed the title Zig build causes segfault Zig build causes segfault when package manager depends on .url from github May 28, 2023
@edyu edyu changed the title Zig build causes segfault when package manager depends on .url from github Zig build causes segfault when package manager depends on .url from github with https May 28, 2023
@edyu
Copy link
Contributor Author

edyu commented May 28, 2023

#15590

@renerocksai
Copy link

zig build segfaults at least 33% of the time if it needs to fetch packages. it has done so for a while. this issue was shadowed by more frequent TLS bugs before. I can't poinpoint to where exactly it is crashing until we get zig debug builds.

I run nightly CI builds and the chance of waking up to a segfaulted build is > 33%

@edyu
Copy link
Contributor Author

edyu commented Jun 24, 2023

One thing I know that segfault happens is when network is spotty. I believe one of the reason is that when network is spotty, the package fetched is either incomplete or 0 bytes and somehow the code is trying to read that which would cause segfault. I've noticed I can make this happen on my computer when my network is crappy but if it run it enough times, network would be intermittent ok and then it would be ok.

@edyu
Copy link
Contributor Author

edyu commented Jun 24, 2023

I want to show an example of the problem. This is from a new machine that was just setup so there is nothing in the zig cache. You can see zig build would segfault multiple times and eventually would work...

~/w/z/blocktube main• ❱ zig build
fish: Job 1, 'zig build' terminated by signal SIGSEGV (Address boundary error)
~/w/z/blocktube main• 3.8s | 139 ❱ zig build
fish: Job 1, 'zig build' terminated by signal SIGSEGV (Address boundary error)
~/w/z/blocktube main• 1.2s | 139 ❱ zig build
fish: Job 1, 'zig build' terminated by signal SIGSEGV (Address boundary error)
~/w/z/blocktube main• 1.2s | 139 ❱ zig build
fish: Job 1, 'zig build' terminated by signal SIGSEGV (Address boundary error)
~/w/z/blocktube main• 3s | 139 ❱ zig build
~/w/z/blocktube main• 38s ❱ ls

@andrewrk
Copy link
Member

Can you reproduce the issue with a debug build of the compiler?

@edyu
Copy link
Contributor Author

edyu commented Jun 27, 2023

Can you reproduce the issue with a debug build of the compiler?

If you can point me to what I need to do and I'll try.

@renerocksai
Copy link

renerocksai commented Jun 27, 2023

Can you reproduce the issue with a debug build of the compiler?

If you can point me to what I need to do and I'll try.

Check out the zig wiki on GitHub. I would start here: https://github.com/ziglang/zig/wiki/Contributing#editing-source-code - contains a link to building from source but focusses on editing and running your modified version, e.g. when you put print debug statements in there etc.

BTW make sure you don't build release when you copy the command line flags 🙂.

@edyu
Copy link
Contributor Author

edyu commented Jun 28, 2023

0.11.0-dev.3879+5804f3f75 is the version I'm running now

@andrewrk andrewrk added this to the 0.11.0 milestone Jul 23, 2023
@andrewrk andrewrk added the standard library This issue involves writing Zig code for the standard library. label Jul 23, 2023
@andrewrk andrewrk removed this from the 0.11.0 milestone Jul 24, 2023
@andrewrk andrewrk added this to the 0.11.1 milestone Jul 24, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0 Jan 29, 2024
@andrewrk andrewrk removed the standard library This issue involves writing Zig code for the standard library. label Jan 31, 2024
@andrewrk andrewrk modified the milestones: 0.12.0, 0.13.0 Jan 31, 2024
@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
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

5 participants