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

deadlock when zig test -lc is run simultaneously with zig run -lc #7659

Closed
FireFox317 opened this issue Jan 2, 2021 · 2 comments
Closed
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@FireFox317
Copy link
Contributor

This came up when trying to hookup the new LLVM backend of the self-hosted compiler to the test-stage2.

The tests runner of the CBE calls zig run -lc on the c code to execute it, however the tests are already executed with zig test <etc> -lc which causes a deadlock in glibc.buildSharedObjects:

0x00007ffff7acb46b in flock () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7acb46b in flock () from /usr/lib/libc.so.6
#1  0x0000555556663a7f in std.os.flock (fd=8, operation=2)
    at /home/timon/dev/zig/zig-source/lib/std/os.zig:4099
#2  0x00005555564cbfdb in std.fs.Dir.openFileZ (self=..., 
    sub_path=0x7fffffff4990 "23fa09cb6f3a41d48e130d0e1309e089.txt", flags=...)
    at /home/timon/dev/zig/zig-source/lib/std/fs.zig:768
#3  0x00005555564c6420 in std.fs.Dir.openFile (self=..., sub_path=..., flags=...)
    at /home/timon/dev/zig/zig-source/lib/std/fs.zig:693
#4  0x00005555564bfd13 in Cache.Manifest.hit (self=0x7fffffff7aa0)
    at /home/timon/dev/zig/zig-source/src/Cache.zig:303
#5  0x00005555565b1c25 in glibc.buildSharedObjects (comp=0x55555e655f08)
    at /home/timon/dev/zig/zig-source/src/glibc.zig:716
#6  0x000055555657fa65 in Compilation.performAllTheWork (self=0x55555e655f08)
    at /home/timon/dev/zig/zig-source/src/Compilation.zig:1551
#7  0x00005555565796b9 in Compilation.update (self=0x55555e655f08)
    at /home/timon/dev/zig/zig-source/src/Compilation.zig:1290
#8  0x000055555651c877 in main.updateModule (gpa=0x55555e563cd0 <c_allocator_state>, 
    comp=0x55555e655f08, zir_out_path=..., hook=...)
    at /home/timon/dev/zig/zig-source/src/main.zig:1953
#9  0x000055555646a26e in main.buildOutputType (gpa=0x55555e563cd0 <c_allocator_state>, 
    arena=0x7fffffffdca8, all_args=..., arg_mode=...)
    at /home/timon/dev/zig/zig-source/src/main.zig:1796
#10 0x0000555556441a85 in main.mainArgs (gpa=0x55555e563cd0 <c_allocator_state>, 
    arena=0x7fffffffdca8, args=...) at /home/timon/dev/zig/zig-source/src/main.zig:167
#11 0x00005555564411ef in main (argc=4, argv=0x7fffffffdee8)
    at /home/timon/dev/zig/zig-source/src/stage1.zig:45

This can be reproduced as follows:
One terminal:

➜  zig-source git:(more-llvm-stage2) ✗ cat bug-stage2.zig 
const std = @import("std");

test "asdf" {
    while (true) {
        std.time.sleep(1000000000);
    }
}%                                                                                                                   
➜  zig-source git:(more-llvm-stage2) ✗ zig test bug-stage2.zig -lc
Test [1/1] test "asdf"... 

Then in the other terminal:

➜  zig-source git:(more-llvm-stage2) ✗ zig run mainstage2.c -lc
@andrewrk
Copy link
Member

andrewrk commented Jan 2, 2021

Related: #7596

@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jan 3, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone Jan 3, 2021
@FireFox317
Copy link
Contributor Author

Has been fixed in 7e5aaca

The glibc_so_files weren't deinitialized which caused a fd to stay open.

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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

2 participants