Skip to content

Commit

Permalink
Ignore requests for non-existent channels
Browse files Browse the repository at this point in the history
This works around a bug in some ssh servers, where channel requests
are sent to channels after the channels have been closed.
  • Loading branch information
jamis committed Feb 1, 2009
1 parent 07ba76a commit f09d124
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,7 @@
=== unreleased

* Ignore requests for non-existent channels (workaround ssh server bug) [Jamis Buck]

* Add terminate! method for hard shutdown scenarios [Jamis Buck]

* Revert to pre-2.0.7 key-loading behavior by default, but load private-key if public-key doesn't exist [Jamis Buck]
Expand Down
12 changes: 11 additions & 1 deletion lib/net/ssh/connection/session.rb
Expand Up @@ -46,6 +46,16 @@ class Session
# The list of callbacks for pending requests. See #send_global_request.
attr_reader :pending_requests #:nodoc:

class NilChannel
def initialize(session)
@session = session
end

def method_missing(sym, *args)
@session.lwarn { "ignoring request #{sym.inspect} for non-existent (closed?) channel; probably ssh server bug" }
end
end

# Create a new connection service instance atop the given transport
# layer. Initializes the listeners to be only the underlying socket object.
def initialize(transport, options={})
Expand All @@ -55,7 +65,7 @@ def initialize(transport, options={})
@options = options

@channel_id_counter = -1
@channels = {}
@channels = Hash.new(NilChannel.new(self))
@listeners = { transport.socket => nil }
@pending_requests = []
@channel_open_handlers = {}
Expand Down
7 changes: 6 additions & 1 deletion test/connection/test_session.rb
Expand Up @@ -257,6 +257,11 @@ def test_channel_window_adjust_packet_should_be_routed_to_corresponding_channel
process_times(2)
end

def test_channel_request_for_nonexistant_channel_should_be_ignored
transport.return(CHANNEL_REQUEST, :long, 14, :string, "testing", :bool, false)
assert_nothing_raised { process_times(2) }
end

def test_channel_request_packet_should_be_routed_to_corresponding_channel
channel_at(14).expects(:do_request).with("testing", false, Net::SSH::Buffer.new)
transport.return(CHANNEL_REQUEST, :long, 14, :string, "testing", :bool, false)
Expand Down Expand Up @@ -480,4 +485,4 @@ def process_times(n)
end
end

end
end

0 comments on commit f09d124

Please sign in to comment.