Skip to content

ChildProcess.exec() on windows hits unreachable #1813

@SpirosMakris

Description

@SpirosMakris

While trying a execute a simple dir command using ChildProcess.exec() on windows 10, the program reaches unreachable code.
An assertion fails in windows.CloseHandle() when trying to close the stderr field of ChildProcess, seemingly because CloseHandle() receives a 0 handle (tried debugging it and the error is invalid handle).

Reproduction code:

const std = @import("std");

pub fn main() !void {
  var a = std.debug.global_allocator;
  const result = try std.os.ChildProcess.exec(
    a,
    [][]const u8{"dir",},
    null,
    null,
    2 * 1024);
}

Stack trace:

reached unreachable code
C:\Zig\lib\zig\std\debug\index.zig:114:9: 0x7ff61db81029 in assert (bug_recreate.obj)
    if (!ok) {
        ^
C:\Zig\lib\zig\std\os\windows\util.zig:42:31: 0x7ff61db98ce2 in windowsClose (bug_recreate.obj)
    assert(windows.CloseHandle(handle) != 0);
                              ^
C:\Zig\lib\zig\std\os\index.zig:221:35: 0x7ff61db889e7 in close (bug_recreate.obj)
        windows_util.windowsClose(handle);
                                  ^
C:\Zig\lib\zig\std\os\child_process.zig:257:69: 0x7ff61dba5bf2 in ChildProcess::ChildProcess_waitUnwrappedWindows (bug_recreate.obj)
            if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {
                                                                    ^
C:\Zig\lib\zig\std\os\child_process.zig:230:17: 0x7ff61dba5986 in ChildProcess::ChildProcess_waitWindows (bug_recreate.obj)
            self.cleanupStreams();
                ^
C:\Zig\lib\zig\std\os\child_process.zig:184:36: 0x7ff61db9f77d in ChildProcess::ChildProcess_wait (bug_recreate.obj)
            return self.waitWindows();
                                   ^
C:\Zig\lib\zig\std\os\child_process.zig:219:9: 0x7ff61db9ef07 in ChildProcess::ChildProcess_exec (bug_recreate.obj)
        try stderr_file_in_stream.stream.readAllBuffer(&stderr, max_output_size);
        ^
E:\SugarSyncSTUFF\PROJECTS\zig\Reworks\std_tests\bug_recreate.zig:5:46: 0x7ff61db9ea52 in main (bug_recreate.obj)
  const result = try std.os.ChildProcess.exec(
                                             ^
C:\Zig\lib\zig\std\special\bootstrap.zig:55:40: 0x7ff61db9e92a in ??? (bug_recreate.obj)
    std.os.windows.ExitProcess(callMain());
                                       ^
???:?:?: 0x7ffa314d1fe4 in ??? (???)


???:?:?: 0x7ffa320acb81 in ??? (???)

Windows 10 and Zig version: 0.3.0+078a0a69

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavioros-windowsMicrosoft Windows

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions