Skip to content

Commit

Permalink
DEVEX-86 Fix Docker blocking on start
Browse files Browse the repository at this point in the history
Startup process was hanging forever and it looked like Docker was responsible. We dug into
the Docker API gem which looked like it was using Excon. It looked like it was using a
blocking connection, so we pass 'nonblock' option to unblock it.

https://github.com/excon/excon/search\?utf8\=%E2%9C%93\&q\=nonblock\&type\=
https://spin.atomicobject.com/2013/09/30/socket-connection-timeout-ruby/
http://www.mikeperham.com/2009/03/15/socket-timeouts-in-ruby/

upserve/docker-api#515
  • Loading branch information
ragurney authored and grosser committed Feb 2, 2018
1 parent afbc23f commit 2dd59cb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions config/initializers/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
Docker.url = url
end

Docker.options = { read_timeout: Integer(ENV['DOCKER_READ_TIMEOUT'] || '10'), connect_timeout: 2 }
Docker.options = {
read_timeout: Integer(ENV['DOCKER_READ_TIMEOUT'] || '10'),
connect_timeout: 2,
nonblock: true
}

begin
Docker.validate_version! # Confirm the Docker daemon is a recent enough version
Expand All @@ -21,12 +25,12 @@
# ensure that --cache-from is supported (v13+)
min_version = 13
begin
Timeout.timeout(1) do
local = Integer(`docker -v`[/Docker version (\d+)/, 1])
server = Integer(Docker.version.fetch("Version")[/\d+/, 0])
if local < min_version || server < min_version
raise Docker::Error::VersionError, "Expected docker version to be >= #{min_version}"
end
local = Timeout.timeout(1) do
Integer(`docker -v`[/Docker version (\d+)/, 1])
end
server = Integer(Docker.version.fetch("Version")[/\d+/, 0])
if local < min_version || server < min_version
raise Docker::Error::VersionError, "Expected docker version to be >= #{min_version}"
end
rescue
warn "Unable to verify local docker!"
Expand Down

0 comments on commit 2dd59cb

Please sign in to comment.