You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Retaining the StandardInputWriter prevents write from happening / being flushed #186
Expected behavior
With the line retainedInputIO = inputIO commented out, the test output is
Test example() started.
bytesWritten: 13
received line: Hello, world!
Test example() passed after 0.008 seconds.
and with this line uncommented I do not see anything received in stdout. The test starts (and never completes, because the program keeps running). Output:
Test example() started.
bytesWritten: 13
<test hangs>
For context, I'm working with a long lived process (MCP over stdio) and I need to be able to continuously read from and write to the subprocess. It also seems that the StandardInputWriter has no flush API that I could use to remediate this issue. Adding new lines to the written content doesn't help with flushing
I think this isn't a valid use of the API and that some of the types provided in the body closure should probably be ~Escapable to prevent this.
Can you restructure your code to ensure that the body closure does not return until you're finished reading and writing? For example, see my PR here which wraps Subprocess in a ProcessController abstraction for long-lived processing: swiftlang/swift-build#638
Test example() started.
bytesWritten: 13
<test hangs>
My use case is that I want to launch a process, and while it is running have access to stdin / stdout in other parts of my code. The subprocess might run for as long as my app is running. It sounds that making those types ~Escapable would prevent this? This would be unfortunate.
Activity
jakepetroules commentedon Oct 21, 2025
I think this isn't a valid use of the API and that some of the types provided in the body closure should probably be ~Escapable to prevent this.
Can you restructure your code to ensure that the body closure does not return until you're finished reading and writing? For example, see my PR here which wraps Subprocess in a ProcessController abstraction for long-lived processing: swiftlang/swift-build#638
gsabran commentedon Oct 21, 2025
Not returning before completing reading / writing doesn't seem to help. Here's what I tried:
which still leads to:
My use case is that I want to launch a process, and while it is running have access to stdin / stdout in other parts of my code. The subprocess might run for as long as my app is running. It sounds that making those types ~Escapable would prevent this? This would be unfortunate.