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

Remove eager closure of unused parent descriptors #102

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ abstract class ProcessBaseTest {
assertTrue(stderrFile.exists())

withContext(Dispatchers.Default) {
p.waitForAsync(2.seconds)
p.waitForAsync(5.seconds)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,53 +41,10 @@ internal class StdioHandle private constructor(

override val isClosed: Boolean get() = stdinFD.isClosed && stdoutFD.isClosed && stderrFD.isClosed
private val lock = Lock()
private var threw: IOException? = null

private val stdin: Instance<WriteStream?> = Instance(create = {
// TODO: Issue #6

// This is invoked once and only once upon NativeProcess
// instantiation (after fork occurs). We can do some descriptor
// clean up here and close unneeded descriptors which were duped
// in the child process and remain open over there.
try {
if (stdinFD is StdioDescriptor.Pipe) {
// Leave write end open here in parent
stdinFD.read
} else {
stdinFD
}.close()
} catch (e: IOException) {
threw?.let { e.addSuppressed(it) }
threw = e
}

try {
if (stdoutFD is StdioDescriptor.Pipe) {
// Leave read end open here in parent
stdoutFD.write
} else {
stdoutFD
}.close()
} catch (e: IOException) {
threw?.let { e.addSuppressed(it) }
threw = e
}

try {
if (stderrFD is StdioDescriptor.Pipe) {
// Leave read end open here in parent
stderrFD.write
} else {
stdoutFD
}.close()
} catch (e: IOException) {
threw?.let { e.addSuppressed(it) }
threw = e
}

if (stdinFD !is StdioDescriptor.Pipe) return@Instance null
if (stdinFD.isClosed) return@Instance null
if (stdinFD !is StdioDescriptor.Pipe) return@Instance null
WriteStream.of(stdinFD)
})

Expand Down Expand Up @@ -139,7 +96,7 @@ internal class StdioHandle private constructor(
private fun closeNoLock() {
if (isClosed) return

var threw: IOException? = threw
var threw: IOException? = null

try {
stdinFD.close()
Expand Down
Loading