Skip to content

Commit e792c9b

Browse files
authored
Merge pull request #1489 from GeorgianaElena/handle-no-space
Don't error out if there's no disk space left when writing the logs
2 parents d850c15 + 1a571bd commit e792c9b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

repo2docker/buildpacks/repo2docker-entrypoint

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# - preserve signal handling of subprocess (kill -TERM and friends)
77
# - tee output to a log file
88

9+
import errno
910
import fcntl
1011
import os
1112
import select
@@ -44,7 +45,7 @@ def main():
4445
break
4546
# raise Exception if log_file could not be set
4647
if log_file is None:
47-
raise Exception("Could not open '.jupyter-server-log.txt' log file " )
48+
raise Exception("Could not open '.jupyter-server-log.txt' log file")
4849

4950
# build the command
5051
# like `exec "$@"`
@@ -73,12 +74,27 @@ def main():
7374
for signum in SIGNALS:
7475
signal.signal(signum, relay_signal)
7576

77+
# keep a record of the output streams that ran out space
78+
writable = {
79+
sys.stdout.buffer: True,
80+
log_file: True
81+
}
82+
7683
# tee output from child to both our stdout and the log file
7784
def tee(chunk):
7885
"""Tee output from child to both our stdout and the log file"""
7986
for f in [sys.stdout.buffer, log_file]:
80-
f.write(chunk)
81-
f.flush()
87+
if writable[f]:
88+
try:
89+
f.write(chunk)
90+
f.flush()
91+
except OSError as e:
92+
if e.errno == errno.ENOSPC:
93+
# mark the stream as not writable anymore
94+
writable[f] = False
95+
continue
96+
else:
97+
raise
8298

8399
# make stdout pipe non-blocking
84100
# this means child.stdout.read(nbytes)
@@ -106,6 +122,8 @@ def main():
106122
tee(chunk)
107123
chunk = child.stdout.read()
108124

125+
log_file.close()
126+
109127
# make our returncode match the child's returncode
110128
sys.exit(child.returncode)
111129

0 commit comments

Comments
 (0)