Skip to content

Commit ef50d97

Browse files
stefwaltermartinpitt
authored andcommitted
unit-tests: Switch stdio to non-blocking after invoking Node.js
Node leaves stdio file descriptors in non-blocking mode when exiting. This has been reported, fixed, unfixed, ad nauseum. nodejs/node#14752 nodejs/node#17737 nodejs/node#20592 nodejs/node#21257 Should this become a problem in more places, we could add such a workaround elsewhere. But for now I'm limiting the ugliness to the unit-tests container, where we see this cause a lot of failures. Closes #9484
1 parent 032d54d commit ef50d97

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

containers/unit-tests/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ RUN dpkg --add-architecture ${arch} && echo ${arch} > /arch && apt-get update &&
2424
RUN npm install -g n && n stable && \
2525
adduser --system --gecos "Builder" builder
2626

27+
# HACK: Working around Node.js screwing around with stdio
28+
ENV NODE_PATH /usr/local/bin/nodejs
29+
RUN mv /usr/local/bin/node /usr/local/bin/nodejs
30+
ADD turd-polish /usr/local/bin/node
31+
2732
USER builder
2833

2934
VOLUME /source

containers/unit-tests/turd-polish

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/python2
2+
3+
# Copyright (C) 2013 Red Hat, Inc.
4+
#
5+
# Cockpit is free software; you can redistribute it and/or modify it
6+
# under the terms of the GNU Lesser General Public License as published by
7+
# the Free Software Foundation; either version 2.1 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# Cockpit is distributed in the hope that it will be useful, but
11+
# WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
# Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public License
16+
# along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
17+
18+
#
19+
# This is certified, A-grade, high quality turd polish. Node leaves
20+
# stdio file descriptors in non-blocking mode when exiting. This has
21+
# been reported, fixed, unfixed, ad nauseum.
22+
#
23+
# https://github.com/nodejs/node/issues/14752
24+
# https://github.com/nodejs/node/pull/17737
25+
# https://github.com/nodejs/node/pull/20592
26+
# https://github.com/nodejs/node/pull/21257
27+
#
28+
# It's starting to fester.
29+
#
30+
31+
import fcntl
32+
import os
33+
import subprocess
34+
import sys
35+
36+
assert "NODE_PATH" in os.environ
37+
proc = subprocess.Popen([ os.environ["NODE_PATH"] ] + sys.argv[1:])
38+
proc.wait()
39+
40+
map(lambda fd: fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) &~ os.O_NONBLOCK), [0, 1, 2])
41+
sys.exit(proc.returncode)

0 commit comments

Comments
 (0)