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

Fix wrong stdin queue order #4

Merged
merged 2 commits into from
Jul 16, 2022

Conversation

Exidnus
Copy link

@Exidnus Exidnus commented Jul 12, 2022

Because of unsafeRunAndForget was used, order of bytes from stdin and order of bytes in stdinQ: Queue[F, ByteVector] could be different. It doesn't look right, so I switched to unsafeRunSync.
And up sbt version to the latest.

@fmonniot
Copy link
Owner

That's a good point, I haven't seen this issue because most of my usages have low throughput. One question I have though: do you know what thread unsafeRunSync block? And is it ok to block it?

@Exidnus
Copy link
Author

Exidnus commented Jul 14, 2022

Sorry for late response, I missed your comment.
Well, good question. Looks like, unsafeRunSync would block on executionContext from Async. So it's a runtime loop from IO and block on it is not a good idea, I think.

@Exidnus
Copy link
Author

Exidnus commented Jul 14, 2022

Well, I thought a little more. :)

  1. ExecutionContext from Async would be used for unsafeRunSync and unsafeRunAndForget, it's no difference here.
  2. Calling unsafeRunSync would block some thread from NuProcess, which we shouldn't block according to javadoc from NuProcessHandler.
    "Note that the processing thread that executes these callbacks on behalf of a NuProcess is the same thread that handles processing for other instances of NuProcess, and as a result you should never perform a blocking or time-consuming operation on the callback thread. Doing so will block or severely hinder the processing of other NuProcess instances. Any operation that requires more than single-digit millisecond processing should be handed off to another thread so that the processing thread can return to immediately service other NuProcess instances." It's from here

So blocking is not an option.

@Exidnus
Copy link
Author

Exidnus commented Jul 14, 2022

But from the other side: there is a Queue.unbounded for stdout and stderr, it's just operation in memory, it's not blocking. So unsafeRunSync looks fine here, no?

Copy link
Owner

@fmonniot fmonniot left a comment

Choose a reason for hiding this comment

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

I believe you are correct, and the offer function should not have blocking underlying it. Let's merge it then.

@fmonniot fmonniot merged commit f3574c7 into fmonniot:master Jul 16, 2022
@fmonniot
Copy link
Owner

0.4.0+3-f3574c73-SNAPSHOT have been released to https://oss.sonatype.org. Let me know if that fixed your issue, and if yes, I'll tag 0.4.1.

@Exidnus
Copy link
Author

Exidnus commented Jul 19, 2022

0.4.0+3-f3574c73-SNAPSHOT have been released to https://oss.sonatype.org. Let me know if that fixed your issue, and if yes, I'll tag 0.4.1.

Thank you. Yes, it solves the problem.

@fmonniot
Copy link
Owner

v0.4.4 have been released to maven central.

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.

None yet

2 participants