Skip to content

Commit

Permalink
Output stdout and stderr when nailgun fails to connect (#5892)
Browse files Browse the repository at this point in the history
Fixes #5853
  • Loading branch information
illicitonion authored and Stu Hood committed Jun 1, 2018
1 parent 2ac8ef8 commit ec0a077
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/python/pants/java/nailgun_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pants.java.executor import Executor, SubprocessExecutor
from pants.java.nailgun_client import NailgunClient
from pants.pantsd.process_manager import FingerprintedProcessManager, ProcessGroup
from pants.util.dirutil import safe_file_dump, safe_open
from pants.util.dirutil import read_file, safe_file_dump, safe_open


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -183,6 +183,7 @@ def _await_socket(self, timeout):
"""Blocks for the nailgun subprocess to bind and emit a listening port in the nailgun stdout."""
with safe_open(self._ng_stdout, 'r') as ng_stdout:
start_time = time.time()
accumulated_stdout = ''
while 1:
readable, _, _ = select.select([ng_stdout], [], [], self._SELECT_WAIT)
if readable:
Expand All @@ -191,10 +192,18 @@ def _await_socket(self, timeout):
return self._NG_PORT_REGEX.match(line).group(1)
except AttributeError:
pass
accumulated_stdout += line

if (time.time() - start_time) > timeout:
stderr = read_file(self._ng_stderr)
raise NailgunClient.NailgunError(
'Failed to read nailgun output after {sec} seconds!'.format(sec=timeout))
'Failed to read nailgun output after {sec} seconds!\n'
'Stdout:\n{stdout}\nStderr:\n{stderr}'.format(
sec=timeout,
stdout=accumulated_stdout,
stderr=stderr,
)
)

def _create_ngclient(self, port, stdout, stderr, stdin):
return NailgunClient(port=port, ins=stdin, out=stdout, err=stderr, workdir=get_buildroot())
Expand Down

0 comments on commit ec0a077

Please sign in to comment.