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

LTA: giving Proc's :err wrongly-opened handle fails silently #2197

Open
zoffixznet opened this issue Aug 10, 2018 · 2 comments
Open

LTA: giving Proc's :err wrongly-opened handle fails silently #2197

zoffixznet opened this issue Aug 10, 2018 · 2 comments
Labels
IO LTA Less Than Awesome; typically an error message that could be better

Comments

@zoffixznet
Copy link
Contributor

Don't know if it's some quirk of the system/shell, but feels buggy:

Here, we open the handle in read mode and give it to Proc's :out/:err.

When given to :out, we get an error about failed write, but if we give the same handle to :err, we get silence:

$ ./perl6 -e 'with $*TMPDIR.add("meows") { .open(:w).close; my $ = run «perl6 -e "note 42"», :err(.open) }'

$ ./perl6 -e 'with $*TMPDIR.add("meows") { .open(:w).close; my $ = run «perl6 -e "say 42"», :out(.open) }'
Failed to write bytes to filehandle: Bad file descriptor
  in block <unit> at -e line 1

$ ./perl6 -v
This is Rakudo version 2018.06-404-g0b3fc07 built on MoarVM version 2018.06-399-g4fc267b
implementing Perl 6.c.
@zoffixznet zoffixznet added LTA Less Than Awesome; typically an error message that could be better IO labels Aug 10, 2018
@schaiba
Copy link

schaiba commented Apr 19, 2021

Still seeing this with 2020.12 . And I get the same error with the following :
my $maxint = (2**31) - 1; say "H" x $maxint; when using the REPL.

@MasterDuke17
Copy link
Contributor

I can repro, I get the error Failed to write bytes to filehandle: Bad address in block <unit> at -e line 1

[dan@alexandria perl6]$ gdb --args ./install/bin/raku -e 'say "H" x 2147483647;'
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./install/bin/raku...
(gdb) b MVM_exception_throw_adhoc
Function "MVM_exception_throw_adhoc" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (MVM_exception_throw_adhoc) pending.
(gdb) r
Starting program: /home/dan/Source/perl6/install/bin/raku -e say\ \"H\"\ x\ 2147483647\;
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff6de3640 (LWP 364039)]

Thread 1 "raku" hit Breakpoint 1, MVM_exception_throw_adhoc (tc=tc@entry=0x55555555a0d0, messageFormat=messageFormat@entry=0x7ffff7a03b80 "Failed to write bytes to filehandle: %s") at src/core/exceptions.c:895
895     MVM_NO_RETURN void MVM_exception_throw_adhoc(MVMThreadContext *tc, const char *messageFormat, ...) {
(gdb) bt
#0  MVM_exception_throw_adhoc (tc=tc@entry=0x55555555a0d0, messageFormat=messageFormat@entry=0x7ffff7a03b80 "Failed to write bytes to filehandle: %s") at src/core/exceptions.c:895
#1  0x00007ffff78dca2e in perform_write (data=0x5555555efd30, buf=0x7ffeebfff010 'H' <repeats 200 times>..., bytes=<optimized out>, tc=0x55555555a0d0) at src/io/syncfile.c:82
#2  perform_write (tc=0x55555555a0d0, data=0x5555555efd30, buf=0x7ffeebfff010 'H' <repeats 200 times>..., bytes=<optimized out>) at src/io/syncfile.c:71
#3  0x00007ffff78dca61 in write_bytes (tc=<optimized out>, h=<optimized out>, buf=0x7ffeebfff010 'H' <repeats 200 times>..., bytes=2147483648) at src/io/syncfile.c:219
#4  0x00007ffff78da399 in MVM_io_write_bytes (tc=0x55555555a0d0, oshandle=<optimized out>, buffer=<optimized out>) at src/io/io.c:158
#5  0x00007ffff7890c3b in MVM_interp_run (tc=0x55555555a0d0, initial_invoke=0x7ffff7a03b80, initial_invoke@entry=0x7ffff79a0e40 <toplevel_initial_invoke>, invoke_data=0x7ffff7a03b80, 
    invoke_data@entry=0x7ffff79a0e40 <toplevel_initial_invoke>, outer_runloop=0xffffffffffffff90, outer_runloop@entry=0x0) at src/core/interp.c:3949
#6  0x00007ffff79a1fa4 in MVM_vm_run_file (instance=instance@entry=0x555555559590, filename=filename@entry=0x555555559520 "/home/dan/Source/perl6/install/share/perl6/runtime/perl6.moarvm") at src/moar.c:504
#7  0x00005555555557c4 in main (argc=<optimized out>, argv=0x7fffffffe338) at src/vm/moar/runner/main.c:472
(gdb)

MasterDuke17 added a commit to MasterDuke17/MoarVM that referenced this issue Apr 19, 2021
In 3734a1d it was changed to cast to
`int`, but that can go negative for large values, which causes a 'Bad
address' error. `raku -e 'say "H" x 2147483647' | wc` now correctly
reports 2147483648 characters written. Fixes the second error reported
in rakudo/rakudo#2197 (comment),
but not the original error of that issue.
MasterDuke17 added a commit to MasterDuke17/MoarVM that referenced this issue Apr 19, 2021
In 3734a1d and a9cb250
they were changed to cast to `int`, but that can go negative for large
values, which causes a 'Bad address' error in the write() case.
`raku -e 'say "H" x 2147483647' | wc` now correctly reports 2147483648
characters written. Fixes the second error reported in
rakudo/rakudo#2197 (comment),
but not the original error of that issue.
MasterDuke17 added a commit to MasterDuke17/MoarVM that referenced this issue Apr 22, 2021
In 3734a1d and a9cb250 they were changed to cast to `int`, but that can
go negative for large values, which causes a 'Bad address' error in the
write() case. Instead, if the value is too big, pass a smaller value and
take advantage of the looping we're already doing.
The max value for write() was suggested by nwc10++ "by the time you're
attempting to write blobs of 1G or greater, it seems a bit nuts to presume
that it matters whether it's 1 system call. It's certainly not going to be
atomic at any lower level"
The max value for send() came from
https://www.ibm.com/docs/en/ztpf/2020?topic=apis-send-send-data-connected-socket
as the minimum of the maximums of the various socket types.
`raku -e 'say "H" x 2147483647' | wc` now correctly reports 2147483648
characters written. Fixes the second error reported in
rakudo/rakudo#2197 (comment), but
not the original error of that issue.
MasterDuke17 added a commit to MasterDuke17/MoarVM that referenced this issue Apr 24, 2021
In 3734a1d and a9cb250 they were changed to cast to `int`, but that can
go negative for large values, which causes a 'Bad address' error in the
write() case. Instead, if the value is too big, pass a smaller value and
take advantage of the looping we're already doing.
The max value was suggested by nwc10++ "by the time you're attempting to
write blobs of 1G or greater, it seems a bit nuts to presume that it
matters whether it's 1 system call. It's certainly not going to be atomic
at any lower level"
and
MoarVM#1474 (comment)
`raku -e 'say "H" x 2147483647' | wc` now correctly reports 2147483648
characters written. Fixes the second error reported in
rakudo/rakudo#2197 (comment), but
not the original error of that issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO LTA Less Than Awesome; typically an error message that could be better
Projects
None yet
Development

No branches or pull requests

3 participants