Skip to content

Commit 5c425b6

Browse files
authored
Merge pull request #190 from nkcsgexi/potential-74058113-fix
Process: only close the read end of the pipe after reading the full content successfully
2 parents 2954e55 + e7d50f1 commit 5c425b6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,14 @@ public final class Process: ObjectIdentifierProtocol {
611611
break loop
612612
}
613613
case 0:
614+
// Close the read end of the output pipe.
615+
// We should avoid closing the read end of the pipe in case
616+
// -1 because the child process may still have content to be
617+
// flushed into the write end of the pipe. If the read end of the
618+
// pipe is closed, then a write will cause a SIGPIPE signal to
619+
// be generated for the calling process. If the calling process is
620+
// ignoring this signal, then write fails with the error EPIPE.
621+
close(fd)
614622
break loop
615623
default:
616624
let data = buf[0..<n]
@@ -621,8 +629,6 @@ public final class Process: ObjectIdentifierProtocol {
621629
}
622630
}
623631
}
624-
// Close the read end of the output pipe.
625-
close(fd)
626632
// Construct the output result.
627633
return error.map(Result.failure) ?? .success(out)
628634
}

0 commit comments

Comments
 (0)