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

ChildProcess.exec() on windows hits unreachable #1813

Closed
SpirosMakris opened this issue Dec 2, 2018 · 1 comment · Fixed by #1919
Closed

ChildProcess.exec() on windows hits unreachable #1813

SpirosMakris opened this issue Dec 2, 2018 · 1 comment · Fixed by #1919
Labels
bug Observed behavior contradicts documented or intended behavior os-windows
Milestone

Comments

@SpirosMakris
Copy link

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

@andrewrk andrewrk added this to the 0.4.0 milestone Dec 2, 2018
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-windows labels Dec 2, 2018
@SpirosMakris
Copy link
Author

After some more testing and debugging, the above happens when ChildProcess can't find the process specified.

If the executable to be run, is in the same directory as the spawing process then everything is fine.

If not, it fails with unreachable, as above , even if the desired process to be run is in the PATH (simple path such as C:\test), and can be succesfully executed from the command line (from any cwd).

Trying to find why the assertion is hit in util.zig:42 :

assert(windows.CloseHandle(handle) != 0);

it seems that CloseHandle is given a null handle (docs specify that it must get a valid handle, I suppose 0 is not valid).

Furthermore a lot of windows processes are given null handles after the process fails to spawn such as WaitForSingleObject.

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 os-windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants