From 2dd59cb0cd2f9f060df44d58d361322237242c50 Mon Sep 17 00:00:00 2001 From: Ryan Gurney Date: Fri, 2 Feb 2018 14:46:11 -0800 Subject: [PATCH] DEVEX-86 Fix Docker blocking on start 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/ https://github.com/swipely/docker-api/issues/515 --- config/initializers/docker.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/config/initializers/docker.rb b/config/initializers/docker.rb index 4886e76f6d..d1010cf2d9 100644 --- a/config/initializers/docker.rb +++ b/config/initializers/docker.rb @@ -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 @@ -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!"