kontena / pharos-cluster

Pharos - The Kubernetes Distribution
https://k8spharos.dev/
Apache License 2.0
311 stars 43 forks source link

pharos-cluster version | head -1: broken pipe error #487

Closed kke closed 5 years ago

kke commented 6 years ago
$ pharos-cluster version | head -1
pharos-cluster version 0.6.2
Broken pipe @ io_write - <STDOUT>
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/version_command.rb:9:in `write'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/version_command.rb:9:in `puts'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/version_command.rb:9:in `puts'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/version_command.rb:9:in `execute'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/clamp-1.2.1/lib/clamp/command.rb:63:in `run'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/clamp-1.2.1/lib/clamp/subcommand/execution.rb:11:in `execute'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/clamp-1.2.1/lib/clamp/command.rb:63:in `run'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/clamp-1.2.1/lib/clamp/command.rb:132:in `run'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/root_command.rb:14:in `run'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/bin/pharos-cluster:12:in `<top (required)>'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/bin/pharos-cluster:23:in `load'
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/bin/pharos-cluster:23:in `<main>'

Same with grep -q (and probably anything that breaks the pipe):

$ pharos-cluster version | grep "pharos-cluster version"
pharos-cluster version 0.6.2
$ pharos-cluster version | grep -q "pharos-cluster version"
Broken pipe @ io_write - <STDOUT>
/__enclose_io_memfs__/lib/ruby/gems/2.4.0/gems/pharos-cluster-0.6.2/lib/pharos/version_command.rb:9:in `write'
...
SpComb commented 6 years ago

As a CLI tool, it would make sense for pharos-cluster to just silently exit on SIGPIPE/EPIPE.

Seems like the ruby default is to ignore SIGPIPE and rise EPIPE from syscalls instead. Looks like the default system behavior of killing the process on SIGPIPE can be explicitly restored using Signal.trap("SIGPIPE", "SYSTEM_DEFAULT"): https://stackoverflow.com/questions/1807355/broken-pipe-errnoepipe/30103307#30103307 (sadly not the most-upvoted answer)

kke commented 6 years ago

Kontena-cli does not do this, I think I may have fixed it somehow intentionally at some point.

kke commented 6 years ago

Yes. https://github.com/kontena/kontena/blob/master/cli/lib/kontena/command.rb#L239

SpComb commented 6 years ago

IMO Signal.trap("SIGPIPE", "SYSTEM_DEFAULT") would be better than rescue Errno::EPIPE => abort, but the result should be more or less the same.

kke commented 5 years ago

Fixed by #602