Skip to content

Commit

Permalink
Fix race condition on Process when more than one IO is specified
Browse files Browse the repository at this point in the history
  • Loading branch information
waj committed Aug 20, 2019
1 parent f544b22 commit 3e45cdb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/process.cr
Expand Up @@ -301,11 +301,13 @@ class Process
fork_io, process_io = IO.pipe(read_blocking: true)

@wait_count += 1
ensure_channel
spawn { copy_io(stdio, process_io, channel, close_dst: true) }
else
process_io, fork_io = IO.pipe(write_blocking: true)

@wait_count += 1
ensure_channel
spawn { copy_io(process_io, stdio, channel, close_src: true) }
end

Expand Down Expand Up @@ -405,6 +407,14 @@ class Process
end

private def channel
if channel = @channel
channel
else
raise "BUG: Notification channel was not initialized for this process"
end
end

private def ensure_channel
@channel ||= Channel(Exception?).new
end

Expand Down

0 comments on commit 3e45cdb

Please sign in to comment.