Skip to content

Commit

Permalink
process_wait can hang if reusing FD in rapid succession. (#126)
Browse files Browse the repository at this point in the history
* Failing test case.

* Unique per-pid/file descriptor.
  • Loading branch information
ioquatix authored Dec 15, 2024
1 parent 6edd6dd commit 8a7b717
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/io/event/selector/epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ VALUE IO_Event_Selector_EPoll_process_wait(VALUE self, VALUE fiber, VALUE _pid,

RB_OBJ_WRITTEN(self, Qundef, fiber);

int result = IO_Event_Selector_EPoll_Waiting_register(selector, 0, descriptor, &waiting);
int result = IO_Event_Selector_EPoll_Waiting_register(selector, _pid, descriptor, &waiting);

if (result == -1) {
close(descriptor);
Expand Down
26 changes: 26 additions & 0 deletions test/io/event/selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,32 @@ def transfer
expect(events).to be == [:process_finished]
expect(result).to be(:success?)
end

it "can wait for two processes sequentially" do
result1 = result2 = nil
events = []

fiber = Fiber.new do
pid1 = Process.spawn("sleep 0.001")
pid2 = Process.spawn("sleep 0.001")

result1 = selector.process_wait(Fiber.current, pid1, 0)
events << :process_finished1

result2 = selector.process_wait(Fiber.current, pid2, 0)
events << :process_finished2
end

fiber.transfer

while fiber.alive?
selector.select(0)
end

expect(events).to be == [:process_finished1, :process_finished2]
expect(result1).to be(:success?)
expect(result2).to be(:success?)
end
end

with "#resume" do
Expand Down

0 comments on commit 8a7b717

Please sign in to comment.