typesafehub / akka-contrib-extra

ConductR Akka contributions
Other
9 stars 16 forks source link

Cannot flush stdin in BlockingProcess #75

Closed MasseGuillaume closed 6 years ago

MasseGuillaume commented 6 years ago

In BlockingProcess the stdin is wrapped in a Stream:

https://github.com/typesafehub/akka-contrib-extra/blob/078eb4745e50c5b21051f67d1f79c0415085c04c/src/main/scala/akka/contrib/process/BlockingProcess.scala#L150-L152

If I send some bytes to stdin, how is it possible to flush them?

MasseGuillaume commented 6 years ago

This is the full context:

In scastie, I was happily using the NonBlockingProcess.

https://github.com/scalacenter/scastie/blob/4c9f0e0b3b5d1c42f9c7a4101f9d8fbae9497a67/utils/src/main/scala/com.olegych.scastie/util/ProcessActor.scala#L83-L120

At some point, we restarted the server and this is when all hell breaks loose. I started getting those errors:

Exception in thread "NuProcessLinuxCwdChangeable-1" java.lang.RuntimeException: unshare(CLONE_FS) failed, return code: -1, last error: 1
        at com.zaxxer.nuprocess.internal.BasePosixProcess.checkReturnCode(BasePosixProcess.java:793)
        at com.zaxxer.nuprocess.internal.BasePosixProcess$LinuxCwdThreadFactory$1.run(BasePosixProcess.java:97)
        at java.lang.Thread.run(Thread.java:748)

https://github.com/brettwooldridge/NuProcess/blob/281bcfc9c019da0891baaf52738b7790f7f13bc0/src/main/java/com/zaxxer/nuprocess/internal/BasePosixProcess.java#L92-L110

I decided, to switch to BlockingProcess to avoid getting this error.

https://github.com/scalacenter/scastie/commit/f871bf90f0df8c62d6d788f2ec856996f0f69148

2m commented 6 years ago

If I send some bytes to stdin, how is it possible to flush them?

flush() is called only on stream completion.

You can pass in autoFlush = true to fromOutputStream to flush everytime a new element is written.

At some point, we restarted the server and this is when all hell breaks loose

Are these related to flushing?

Either way looks like unshare returned a failure. This might want a ticket in https://github.com/brettwooldridge/NuProcess

MasseGuillaume commented 6 years ago

@2m

I think autoFlushStdIn: Boolean should be exposed in the BlockingProcess.props https://github.com/typesafehub/akka-contrib-extra/blob/078eb4745e50c5b21051f67d1f79c0415085c04c/src/main/scala/akka/contrib/process/BlockingProcess.scala#L82-L86

created: https://github.com/brettwooldridge/NuProcess/issues/84

brettwooldridge commented 6 years ago

@MasseGuillaume NuProcess v1.2.0 fixes the "unshare(CLONE_FS)" issue.