croservices / cro

Development tools for building services and distributed systems in Raku using the Cro libraries.
https://cro.services/
Artistic License 2.0
88 stars 34 forks source link

Could not run example in documentation due to error on MacOS #111

Open scovit opened 4 years ago

scovit commented 4 years ago

Then,

Then open a web browser, http://localhost:20000

The page does not show, on the shell the following error:

⚠ hello Cannot flush handle: Failed to flush filehandle: Operation not supported ⚠ hello in block at /usr/local/Cellar/rakudo/2019.07.1/share/perl6/site/sources/794E18F5F4F80DEE905DE049F8655401F940C814 (Cro::HTTP::Log::File) line 28 ⚠ hello in block at /usr/local/Cellar/rakudo/2019.07.1/share/perl6/site/sources/D69ADAA9BE77DD33B9702EA1BCD4D35E6379EA88 (Cro::HTTP::Internal) line 45 ⚠ hello in block at /usr/local/Cellar/rakudo/2019.07.1/share/perl6/site/sources/9A69BC70F2D8C7BD950C926E19009FF093ED8524 (Cro::HTTP::Router) line 232 ⚠ hello

jnthn commented 4 years ago

Does perl6 -e '$*OUT.flush' produce the same error?

scovit commented 4 years ago

Negative: it does not produce any error

jnthn commented 4 years ago

Hm, OK. What about if it's $*ERR? Also, what if it's:

perl6 -e 'react { my $p = Proc::Async.new("perl6", "-e", "\$*OUT.flush"); whenever $p.stdout { }; whenever $p.start { } }'

scovit commented 4 years ago

Good golf!

$ perl6 -e 'react { my $p = Proc::Async.new("perl6", "-e", "\$*OUT.flush"); whenever $p.stdout { }; whenever $p.start { } }'

Cannot flush handle: Failed to flush filehandle: Operation not supported in block at -e line 1

scovit commented 4 years ago

$*ERR is not a problem

$ perl6 -e '$*OUT.flush' | cat Cannot flush handle: Failed to flush filehandle: Operation not supported in block at -e line 1

scovit commented 4 years ago

Seems like a moarvm bug to me.

Since flush is implemented as fsync in moarvm, but..

$ perl6 -e 'use NativeCall; sub fsync(int32 --> int32) is native { }; say fsync(1)' | cat returns -1.

which is right. Since pipes are not synchronous.

jnthn commented 4 years ago

Hm, though it seems to work out on various platforms. I wonder what it should be using...

scovit commented 4 years ago

C fflush is a no-op on pipes.

I suspect that the linux kernel fsync on pipes is also a no-op, on Mac (and possibly freebsd) it returns errors.

scovit commented 4 years ago

Sorry I cannot help you in deciding what it should be. I am not enough a POSIX expert