Skip to content

Commit

Permalink
Fix seek error thrown when creating read stream in Node 8
Browse files Browse the repository at this point in the history
Early Node 8 versions have a bug that force a seek upon creation of a read stream. The workaround is to pass the file descriptor directly. See: nodejs/node#19240

Change-Type: patch
  • Loading branch information
dfunckt committed Mar 28, 2018
1 parent 5e4df74 commit 9caf3e9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
File renamed without changes.
29 changes: 29 additions & 0 deletions Dockerfile.node8.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM resin/intel-nuc-node:8

VOLUME /var/lib/docker

RUN apt-get update \
&& apt-get install -y aufs-tools rsync iptables \
&& rm -rf /var/lib/apt/lists/*

ENV DOCKER_VERSION 1.11.2
RUN wget -q -O /tmp/docker-${DOCKER_VERSION}.tgz https://get.docker.com/builds/Linux/x86_64/docker-${DOCKER_VERSION}.tgz \
&& tar xvfz /tmp/docker-${DOCKER_VERSION}.tgz -C /tmp \
&& cp -r /tmp/docker/* /usr/bin/ \
&& rm -rf /tmp/docker \
&& chmod +x /usr/bin/docker*

WORKDIR /usr/src/app

COPY package.json /usr/src/app/

RUN npm install --unsafe-perm && npm cache clean

COPY . /usr/src/app

COPY test/services/ /etc/systemd/system/

ENV INITSYSTEM on

RUN systemctl enable docker
CMD docker info
10 changes: 9 additions & 1 deletion lib/rsync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ exports.createRsyncStream = (src, dest) ->
ps.stderr.pipe(process.stderr)
ps.stdout.pipe(process.stdout)

resolve(fs.createReadStream(pipePath).on('close', cleanup))
# Early Node 8 versions have a bug that force a seek upon creation of
# a read stream. The workaround is to pass the file descriptor directly.
# See: https://github.com/nodejs/node/issues/19240
fs.open pipePath, 'r', (err, fd) ->
if err
cleanup()
reject(err)
else
resolve(fs.createReadStream(undefined, fd: fd).on('close', cleanup))
9 changes: 7 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ function cleanup() {
}
trap cleanup EXIT

docker build -f Dockerfile.test -t localhost/docker-delta-test .
docker build -f Dockerfile.node6.test -t localhost/docker-delta-node6-test .
docker run --privileged --name deltatest -d localhost/docker-delta-node6-test
docker exec deltatest bash -c "npm run lint && ./node_modules/.bin/mocha --compilers coffee:coffee-script/register"

cleanup
docker run --privileged --name deltatest -d localhost/docker-delta-test

docker build -f Dockerfile.node8.test -t localhost/docker-delta-node8-test .
docker run --privileged --name deltatest -d localhost/docker-delta-node8-test
docker exec deltatest bash -c "npm run lint && ./node_modules/.bin/mocha --compilers coffee:coffee-script/register"

0 comments on commit 9caf3e9

Please sign in to comment.