Skip to content

Broken pipe if stdout is piped to head utility #7810

Open
@petr-fischer

Description

@petr-fischer

Code to reproduce:

1.to 1000 { |i| puts "123456789012345678901234567890123456789012345678901234567890 #{i}" }

Then, when I try to pipe with command:

crystal src/head_io_bug.cr | head

This error output occurs:

123456789012345678901234567890123456789012345678901234567890 1
123456789012345678901234567890123456789012345678901234567890 2
123456789012345678901234567890123456789012345678901234567890 3
123456789012345678901234567890123456789012345678901234567890 4
123456789012345678901234567890123456789012345678901234567890 5
123456789012345678901234567890123456789012345678901234567890 6
123456789012345678901234567890123456789012345678901234567890 7
123456789012345678901234567890123456789012345678901234567890 8
123456789012345678901234567890123456789012345678901234567890 9
123456789012345678901234567890123456789012345678901234567890 10
Unhandled exception: Error writing file: Broken pipe (Errno)
  from /usr/local/lib/crystal/crystal/system/unix/file_descriptor.cr:79:13 in 'unbuffered_write'
  from /usr/local/lib/crystal/io/buffered.cr:179:5 in 'flush'
  from /usr/local/lib/crystal/io/buffered.cr:131:7 in 'write'
  from /usr/local/lib/crystal/io.cr:481:7 in 'write_utf8'
  from /usr/local/lib/crystal/string.cr:4254:5 in 'to_s'
  from /usr/local/lib/crystal/io.cr:184:5 in '<<'
  from /usr/local/lib/crystal/io.cr:227:5 in 'puts'
  from /usr/local/lib/crystal/kernel.cr:366:3 in 'puts'
  from /usr/local/lib/crystal/int.cr:410:7 in '__crystal_main'
  from /usr/local/lib/crystal/crystal/main.cr:97:5 in 'main_user_code'
  from /usr/local/lib/crystal/crystal/main.cr:86:7 in 'main'
  from /usr/local/lib/crystal/crystal/main.cr:106:3 in 'main'
  from _start
  from ???
Failed to raise an exception: 7431104
[0x449bd6] *CallStack::print_backtrace:Int32 +118
[0x430456] __crystal_raise +86
[0x466c74] *IO::FileDescriptor +260
[0x466b03] *IO::FileDescriptor +83
[0x489d6c] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +156
[0x43ab36] main +6
[0x42f7e5] _start +149
[0x8006be000] ???

version:

Crystal 0.28.0 (2019-04-18)

LLVM: 6.0.1
Default target: x86_64-portbld-freebsd11.2
(broken also on Linux/Ubuntu Linux, same behaviour)

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.topic:stdlib:filestough-cookieMulti-faceted and challenging topic, making it difficult to arrive at a straightforward decision.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions