Permalink
Browse files

Stop streaming after client disconnects

  • Loading branch information...
Matthew Boedicker and Pieter Noordhuis
Matthew Boedicker and Pieter Noordhuis committed Mar 25, 2013
1 parent fb9aea0 commit eef059c77deb316af8473ad68487fd7c7b86dc2e
Showing with 27 additions and 0 deletions.
  1. +9 −0 warden/lib/warden/server.rb
  2. +18 −0 warden/spec/support/examples/running_commands.rb
@@ -329,11 +329,18 @@ def post_init
@closing = false
@requests = []
@buffer = Protocol::Buffer.new
+ @bound = true
Server.drainer.register_connection(self)
end
+ def bound?
+ @bound
+ end
+
def unbind
+ @bound = false
+
f = Fiber.new { emit(:close) }
f.resume
@@ -483,6 +490,8 @@ def process_container_request(request, container)
when Protocol::StreamRequest
response = container.dispatch(request) do |name, data|
+ break if !bound?
+
response = request.create_response
response.name = name
response.data = data
@@ -169,6 +169,24 @@ def stream(client, job_id)
end.to raise_error(Warden::Client::ServerError, "no such job")
end
+ it "should stream a finished job after another connection streamed and was terminated before completion" do
+ job_id = client.spawn(:handle => handle, :script => "for i in $(seq 2); do echo $i; sleep 0.1; done").job_id
+
+ client.write(Warden::Protocol::StreamRequest.new(:handle => handle, :job_id => job_id))
+
+ client.disconnect
+
+ sleep 0.3
+
+ client.reconnect
+
+ # Attempt to stream the job again; the server should have left it in tact
+ r = stream(client, job_id)
+ r.select { |e| e.name == "stdout" }.collect(&:data).join.should == "1\n2\n"
+ r.select { |e| e.name == "stderr" }.collect(&:data).join.should == ""
+ r.last.exit_status.should == 0
+ end
+
describe "on different connections" do
let(:c1) { create_client }
let(:c2) { create_client }

0 comments on commit eef059c

Please sign in to comment.