Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exec doesn't time out when passing stdin #546

Open
aramgre opened this issue Feb 28, 2019 · 0 comments
Open

Exec doesn't time out when passing stdin #546

aramgre opened this issue Feb 28, 2019 · 0 comments

Comments

@aramgre
Copy link

aramgre commented Feb 28, 2019

container = Docker::Container.create(Image: 'debian:latest', Cmd: ['sleep', 'infinity'])
container.start
container.exec(['sleep', 'infinity'], wait: 5)
# Docker::Error::TimeoutError (read timeout reached)

container.exec(['sleep', 'infinity'], wait: 5, stdin: StringIO.new('hello'))
# hangs

container.exec(['bash', '-c', 'cat; sleep infinity'], wait: 5, stdin: StringIO.new('hello'))
# hangs

Hijacking the Excon socket instead of the underlying socket gets the timeout to work again but I don't know if that would break anything else:

diff --git a/lib/docker/util.rb b/lib/docker/util.rb
index 2ca8dc6..432f26e 100644
--- a/lib/docker/util.rb
+++ b/lib/docker/util.rb
@@ -65,10 +65,10 @@ module Docker::Util
       debug "hijack: starting stdin copy thread"
       threads << Thread.start do
         debug "hijack: copying stdin => socket"
-        IO.copy_stream stdin, socket
+        socket.write stdin.read
 
         debug "hijack: closing write end of hijacked socket"
-        close_write(socket)
+        close_write(socket.instance_variable_get(:@socket))
       end
 
       debug "hijack: starting hijacked socket read thread"
@@ -76,7 +76,7 @@ module Docker::Util
         debug "hijack: reading from hijacked socket"
 
         begin
-          while chunk = socket.readpartial(512)
+          while chunk = socket.read(512)
             debug "hijack: got #{chunk.bytesize} bytes from hijacked socket"
             attach_block.call chunk, nil, nil
           end
diff --git a/lib/excon/middlewares/hijack.rb b/lib/excon/middlewares/hijack.rb
index 727cf29..b2b731c 100644
--- a/lib/excon/middlewares/hijack.rb
+++ b/lib/excon/middlewares/hijack.rb
@@ -39,7 +39,7 @@ module Excon
           datum[:response] = build_response(status, socket)
 
           Excon::Response.parse_headers(socket, datum)
-          datum[:hijack_block].call socket.instance_variable_get(:@socket)
+          datum[:hijack_block].call(socket)
         end
 
         @stack.response_call(datum)
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant