Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flush stdout buffer when writing data #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gsabran
Copy link

@gsabran gsabran commented Dec 27, 2024

Flush stdout buffer when writing data. I noticed that without an extra line break, the receiver was not getting the message written to stdout.

As a nit (happy to revert) I thought that stdio was clearer that stdioPipe as afaik piping is specific to shell scripts, and stdin can be written to in other contexts.

@mattmassicotte
Copy link
Contributor

I'm afraid this isn't a safe change. Introducing new data like this will break some existing communication protocols. However! I do think the underlying problem you discovered should still be fixed. Perhaps we can do it another way?

(and yes I 100% agree with your nit, thanks for calling that out!)

@gsabran
Copy link
Author

gsabran commented Dec 28, 2024

Introducing new data like this will break some existing communication protocols.

This only applies to when using the process' stdio though. ie other communication protocols (for ex websocket) are not impacted.

As an alternative, what do you think of

@available(*, deprecated, renamed: "stdio", message: "Use stdio instead")
public static func stdioPipe() -> DataChannel {
  stdio(flushOnWrite: false)
}

public static func stdio(flushOnWrite: Bool = true) -> DataChannel { ... }

@mattmassicotte
Copy link
Contributor

This only applies to when using the process' stdio though. ie other communication protocols (for ex websocket) are not impacted.

That's true! This transport just happens to be really important for my own uses.

I think it is critical that transports faithfully write only the data that a user actually intends. I'm much more inclined to use an out-of-band mechanism here like fflush. This would have the exact same behavior but not alter the data stream in any way.

What do you think about keeping non-flushing behavior the default, so existing clients continue to work, and look into using fflush?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants