Skip to content

Commit 2d83374

Browse files
author
Jonathon Belotti
authored
Fix bug in image puller execution timeout (#1495)
* repository_ctx.execute must also receive 'timeout' value otherwise limit is default 600s * make test test by updating expected err, and add note about potential test flakiness
1 parent 2f2ffed commit 2d83374

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

container/pull.bzl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ exports_files(["image.digest", "digest"])
165165
kwargs = {}
166166

167167
if "PULLER_TIMEOUT" in repository_ctx.os.environ:
168-
args += [
169-
"-timeout",
170-
repository_ctx.os.environ.get("PULLER_TIMEOUT"),
171-
]
168+
timeout_in_secs = repository_ctx.os.environ["PULLER_TIMEOUT"]
169+
if timeout_in_secs.isdigit():
170+
args += [
171+
"-timeout",
172+
timeout_in_secs,
173+
]
174+
kwargs["timeout"] = int(timeout_in_secs)
175+
else:
176+
fail("'%s' is invalid value for PULLER_TIMEOUT. Must be an integer." % (timeout_in_secs))
172177

173178
result = repository_ctx.execute(args, **kwargs)
174179
if result.return_code:

testing/e2e/puller.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ function test_puller_timeout() {
2525
# Ensure the puller respects the PULLER_TIMEOUT environment variable. Try
2626
# pulling a large image but set a very low timeout of 1s which should fail if
2727
# the puller is respecting timeouts.
28+
# NOTE: Potential race condition between the Bazel timeout mechanism and the go puller's.
29+
# Could result in test flakes.
30+
# See: https://github.com/bazelbuild/rules_docker/pull/1495#issuecomment-627969114
2831
cd "${ROOT}"
29-
EXPECT_CONTAINS "$(PULLER_TIMEOUT=1 bazel build @large_image_timeout_test//image 2>&1)" "i/o timeout"
32+
EXPECT_CONTAINS "$(PULLER_TIMEOUT=1 bazel build @large_image_timeout_test//image 2>&1)" "ERROR: Pull command failed: Timed out"
3033
echo "test_puller_timeout PASSED!"
3134
}
3235

33-
test_puller_timeout
36+
test_puller_timeout

0 commit comments

Comments
 (0)