Capistrano3のdeployでErrno::EINVAL: Invalid argument – recvfrom(2)

Capistranoでdeployコマンドを実行した時、git:checkタスクで以下エラーとなり失敗する。

bundle exec cap production deploy
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host <example.com>: Invalid argument - recvfrom(2)

Caused by:
Errno::EINVAL: Invalid argument - recvfrom(2)

環境

  • Ubuntu 14.04.5 LTS (Bash on Windows)
  • ruby 2.3.3
  • bundler 1.16.1
Gemfile.lock
    capistrano (3.10.1)
      airbrussh (>= 1.0.0)
      i18n
      rake (>= 10.0.0)
      sshkit (>= 1.9.0)
    capistrano-bundler (1.3.0)
      capistrano (~> 3.1)
      sshkit (~> 1.2)
    capistrano-rails (1.3.1)
      capistrano (~> 3.1)
      capistrano-bundler (~> 1.1)
    capistrano-rbenv (2.1.3)
      capistrano (~> 3.1)
      sshkit (~> 1.3)
    capistrano-rbenv-vars (0.1.0)
      capistrano (>= 3.0)
      capistrano-rbenv (>= 2.0)
    capistrano3-puma (3.1.1)
      capistrano (~> 3.7)
      capistrano-bundler
      puma (~> 3.4)
    sshkit (1.15.1)
      net-scp (>= 1.1.2)
      net-ssh (>= 2.8.0)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-ssh (4.2.0)

# 他省略

原因

net-ssh-4.2.0で発生しているよう
recv(n)で例外を吐いている。

net-ssh-4.2.0/lib/net/ssh/bufferd_io.rb
    def fill(n=8192)
      input.consume!
      data = recv(n)
      debug { "read #{data.length} bytes" }
      input.append(data)
      return data.length
    rescue EOFError => e
      @input_errors << e
      return 0
    end

以下が参考になりそうだったが、よくわからなかった…
https://docs.ruby-lang.org/ja/latest/method/BasicSocket/i/recv.html
http://pubs.opengroup.org/onlinepubs/009695399/functions/recvfrom.html

回避策

色々調べたが情報がほとんど無く未解決
とりあえずsshではなくhttpsでcloneするようにしたらエラーは出なくなりました。

deploy.rb
#set :repo_url, 'git@bitbucket.org:hoge/fuga.git'
set :repo_url, 'https://hoge@bitbucket.org/hoge/fuga.git'