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

Don't block FRP network if writing to stdin blocks #11

Merged
merged 10 commits into from May 8, 2020

Conversation

meditans
Copy link
Member

This PR solves #9

The way this was done is adding a TChan to act as an unbounded buffer between the FRP network and the stdin handle. There's also a test suite that checks for this property. I suggest running the test suite with:

nix-shell -E '((import ./reflex-platform {}).ghc.callCabal2nix "reflex-process" ./. {}).env' --run 'cabal test --test-show-details=streaming'

so that one can check both the output of the cat process, and the eventual messages that arise from a blocking process (for now, I have a broken pipe that arises from the way I'm handling the finally clause in the test suite).

@meditans meditans force-pushed the cn-#9-dont-block-network-when-child-blocks-stdin branch from b2b25bb to dcbdf25 Compare April 24, 2020 19:31
src/Reflex/Process.hs Outdated Show resolved Hide resolved
Copy link
Member

@tomsmalley tomsmalley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, but we should move the headless host stuff elsewhere.

src/Reflex/Process.hs Outdated Show resolved Hide resolved
@lspitzner
Copy link

lspitzner commented Apr 29, 2020

I am mildly certain that TChan is overkill. Control.Concurrent.Chan would do, and even Data.IORef.IORef using atomicModifyIORef would work. Afaik, IORef [a] serves fine as a channel as long as you have a single consumer that can always drain all elements (EDIT: and the consumer must not need to block, which this code does need.) Which you could do here, even though it adds a bit of boilerplate.

I'll let the maintainers of this decide whether they want the IORef performance or the Chan maintainability.

@lspitzner
Copy link

Oh wait, IORef cannot block. Whoops. Needs Chan.

@3noch
Copy link
Member

3noch commented Apr 29, 2020

@lspitzner The only reason we went with TChan is it affords a slightly nicer API if you need it, but seeing that we're not exposing the channel itself it's probably moot.

@3noch
Copy link
Member

3noch commented Apr 30, 2020

@lspitzner I think we should actually expose the TChan which makes me prefer TChan over Chan because TChan has a much richer API, particularly if you hope to build a pressure relief valve since it is unbounded.

@lspitzner
Copy link

true, I approve.

src/Reflex/Process.hs Outdated Show resolved Hide resolved
src/Reflex/Process.hs Outdated Show resolved Hide resolved
@3noch
Copy link
Member

3noch commented Apr 30, 2020

Then again, just abstracting this a bit more makes the choice of channel a trivial configuration. Will go that route instead.

src/Reflex/Process.hs Outdated Show resolved Hide resolved
@3noch 3noch mentioned this pull request Apr 30, 2020
@3noch 3noch requested a review from tomsmalley May 8, 2020 20:04
@3noch 3noch dismissed tomsmalley’s stale review May 8, 2020 20:05

Comments have been resolved

@3noch 3noch merged commit e2b6477 into develop May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants