diff --git a/CHANGELOG.md b/CHANGELOG.md index 594e39fb..396eae17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### 0.9.2 (Next) * [#161](https://github.com/slack-ruby/slack-ruby-client/pull/161): Added support for cursor pagination - [@dblock](https://github.com/dblock). +* [#162](https://github.com/slack-ruby/slack-ruby-client/pull/162): Gracefully close websocket on Errno::EPIPE - [@johanoskarsson](https://github.com/johanoskarsson). * Your contribution here. ### 0.9.1 (8/24/2017) diff --git a/lib/slack/real_time/concurrency/celluloid.rb b/lib/slack/real_time/concurrency/celluloid.rb index d5ddb57c..9a277e48 100644 --- a/lib/slack/real_time/concurrency/celluloid.rb +++ b/lib/slack/real_time/concurrency/celluloid.rb @@ -34,7 +34,7 @@ def run_loop @connected = @socket.connect driver.start loop { read } if socket - rescue EOFError => e + rescue EOFError, Errno::EPIPE => e logger.debug("#{self.class}##{__method__}") { e } driver.emit(:close, WebSocket::Driver::CloseEvent.new(1001, 'server closed connection')) unless @closing ensure diff --git a/spec/slack/real_time/concurrency/celluloid_spec.rb b/spec/slack/real_time/concurrency/celluloid_spec.rb index 51d7aa56..58ffc5d0 100644 --- a/spec/slack/real_time/concurrency/celluloid_spec.rb +++ b/spec/slack/real_time/concurrency/celluloid_spec.rb @@ -43,6 +43,22 @@ def read socket.run_loop end end + + describe '#run_loop with epipe' do + let(:test_socket) do + Class.new(described_class) do + def read + fail Errno::EPIPE + end + end + end + + it 'runs' do + expect(ws).to receive(:emit) + expect(ws).to receive(:start) + socket.run_loop + end + end end pending 'send_data'