coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

comm: avoid deadlock when both inputs are stdin

Open darkraider01 opened this issue 1 month ago • 2 comments

This is one of the remaining GNU 9.12 test failures from #14705 (comm/dash-dash.sh).

Right now comm - - hangs instead of reading both inputs from stdin.

I traced it to the stdin handling in comm: each - goes through open_file(), which creates its own long-lived StdinLock. The first lock is still held when the second input tries to lock stdin again, so it blocks.

This also seems related to #9085, where stdin was changed to stay locked for the duration of the program. There’s also a note there mentioning that calling Stdin::lock() more than once in this single-threaded path can deadlock.

GNU allows both - operands to read from the same stdin stream, so I think we should keep a single stdin lock and share it between the two LineReaders instead of trying to acquire it twice.

I'd like to take this and add a regression test for comm - -.

References:

  • #14705
  • #9085
  • GNU test: tests/comm/dash-dash.sh

darkraider01 avatar Oct 08 '26 06:10 darkraider01

Dupe of https://github.com/uutils/coreutils/issues/14219 .

The solution is specialized for stdin. We need to support general two same FIFOs. See https://github.com/uutils/coreutils/issues/14219#issuecomment-5458576349 .

oech3 avatar Oct 08 '26 07:10 oech3

Ah yep, I missed #14219 while checking the tracker. Thanks for pointing it out — I'll close this as a duplicate and continue there instead.

darkraider01 avatar Oct 08 '26 07:10 darkraider01