Skip to content

Fatal error "FileDescriptor 3 was not closed" on Windows #84

@stefanspringer1

Description

@stefanspringer1

Describe the bug

A simple call to run results in "Fatal error: FileDescriptor 3 was not closed" on Windows.

To Reproduce

The following main program:

let _ = try await run(.path(#"C:\tmp\Hello.exe"#))

calls the program "Hello.exe" which has the following code:

print("hello")

Expected behavior

Expected is that Hello.exe runs, prints "hello" and no error occurs.

Environment:

  • Windows 11
  • Swift version 6.1.2 (swift-6.1.2-RELEASE), Target: x86_64-unknown-windows-msvc
  • swift-subprocess 80bd50f from 2025-06-13

Additional context

It might have something to do with #72.

Activity

stefanspringer1

stefanspringer1 commented on Jun 15, 2025

@stefanspringer1
Author

Aha, of course the program does not wait. This explains it.

stefanspringer1

stefanspringer1 commented on Jun 15, 2025

@stefanspringer1
Author

Hmm... The following code works on macOS (with another path to the executable), but on Windows it outputs the "Fatal error: FileDescriptor 3 was not closed" above.

let semaphore = DispatchSemaphore(value: 0)
DispatchQueue.global(qos: .userInitiated).async {
    Task {
        print("calling...")
        let result = try await run(.path(#"C:\tmp\Hello.exe"#))
        print(result.standardOutput)
        semaphore.signal()
        print("done calling")
    }
}
print("Waiting for call to finish...")
semaphore.wait()
print("DONE ALL")

So there does seem to a problem.

self-assigned this
on Jun 16, 2025
kcieplak

kcieplak commented on Jun 19, 2025

@kcieplak

I am as well seeing the same failure.

13:23:09  Build of product 'spi-metrics-collector' complete! (25.42s)
13:23:10  Subprocess/Configuration.swift:636: Fatal error: FileDescriptor 3 was not closed
13:23:10  Current stack trace:
13:23:10  0    spi-metrics-collector.exe          0x00007ff739ee638c <unavailable> + 1270668
13:23:10  1    KERNEL32.DLL                       0x00007ffbd6e68700 BaseThreadInitThunk + 64
13:23:10  2    ntdll.dll                          0x00007ffbd7938280 RtlUserThreadStart + 68

The code is simply doing a Subprocess.run and trying to get the status and stdout.

let versionResult = try await Subprocess.run(.name("swift-build"), arguments: ["--version"])
        if versionResult.terminationStatus == .exited(0) {
            swiftVersion = versionResult.standardOutput!
                .replacingOccurrences(of: "Swift Package Manager - Swift ", with: "")
                .trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
        }
added a commit that references this issue on Jun 30, 2025
c31f191
added a commit that references this issue on Jun 30, 2025
8db9609
added a commit that references this issue on Jul 2, 2025
f835957
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

blockerShow stopping issues for 0.0.1bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @iCharlesHu@stefanspringer1@kcieplak

    Issue actions

      Fatal error "FileDescriptor 3 was not closed" on Windows · Issue #84 · swiftlang/swift-subprocess