Uploaded image for project: 'Swift'
  1. Swift
  2. SR-12084

EBADF when trying to close the Foundation's fileHandle of a pipe before running the task

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Foundation
    • Labels:

      Description

      description

      The following program spawns /usr/bin/env and tries to close fileHandleForWriting for stdin.

      This was run on Linux and it always crashes with: Fatal error: POSIX command failed with error: 9 – EBADF. On macOS works fine.

      This affects Swift 5.1, but seems to be working on the latest master snapshot probably due to this PR.

      program

      import Foundation
      
      let process = Process()
      process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
      
      let inputPipe = Pipe()
      try! inputPipe.fileHandleForWriting.close()
      process.standardInput = inputPipe
      try! process.run() 

      Repro:

      on Linux

      swift File.swift && ./File 

      on macOS (via docker)

      # assuming File.swift is in the working directory
      docker run --privileged --rm -v "$PWD:$PWD" -w "$PWD" -it swift:5.1 bash -c 'swiftc File.swift && ./File' 

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            rignatus Raul Ignatus
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: