Page MenuHome GnuPG

gpgscm: call-with-io deadlock when larger stderr output
Testing, LowPublic

Description

call-with-io spawns a process, then writes input string to stdin, then reads out all output from stdout, reads out all ouptput from stderr... of spawned process.

This works in most cases, given there is enough room for pipe buffer, like 4096-byte on POSIX machine.

However, when the spawned process writes larger output to stderr and blocked because of no room of pipe buffer, it hangs (other end process is waiting on stdout to read, while another end process waiting stderr on write).
It occurs on Windows, when testing with verbose=3, for example, where default pipe buffer size is small.
We can work around that to tweak the buffer size with CreatePipe argument, but it's not final solution (because it may hang by more larger output).

Solution would be having a loop to drain data through both pipes (of stdout and stderr). For POSIX machine, we can use select on those pipes.
For Windows, we can do either:
(1) Don't use CreatePipe but use CreateNamedPipe with FILE_FLAG_OVERLAPPED, and taking advantage of asynchronous I/O to detect one of pipes ir ready.
(2) Spawn a thread to drain stderr pipe, draining data from stdout pipe

Revisions and Commits

Event Timeline

gniibe created this task.

I modified ffi.c, to have renamed process-spawn-io function doing I/O by C.

gniibe changed the task status from Open to Testing.Jun 8 2023, 7:43 AM

Fixed in master.