-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncate BUILDKITE_MESSAGE to 64 KiB #1307
Conversation
Should help #1269 |
045da71
to
1ced820
Compare
Otherwise a large commit message can cause complete failure: fork/exec ./buildkite-agent: argument list too long Environment size is included in "argument list" limit, which varies by system: macOS 10.15: 256 KiB shared by environment & argv Linux 4.19: 128 KiB per k=v env Windows 10: 16,384 KiB shared POSIX: 4 KiB minimum shared
1ced820
to
7983d9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great research and write up, I learnt a bunch!
Is this only truncating BUILDKITE_MESSAGE
, and if so... is there any value in truncating all env values we pass to bootstrap? Most are very unlikely to exceed 64kb (in some cases it's impossible), but the code might be slightly simpler and it might just catch another edge case.
I wondered that…
That was half the reason I didn't. Also also, we'd probably want a conditional to prevent the |
makes sense 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a commit with a message of ~200Kb, and tried to build it.
With an agent built from master, it failed as you described.
With an agent built from this branch, it ran successfully. Nice 👍
It's interesting that BUILDKITE_MESSAGE
looks un-truncated through the UI. I can see the truncation in the agent log output, but that won't be visible to end users.
2020-09-24 20:56:27 DEBUG tak-1 [JobRunner] Created env file: /tmp/job-env-69dd93df-a91a-484a-a1b5-4a02dc184458300191490
2020-09-24 20:56:27 WARN tak-1 BUILDKITE_MESSAGE value truncated 204999 -> 65517 bytes
2020-09-24 20:56:27 INFO tak-1 Starting job 69dd93df-a91a-484a-a1b5-4a02dc184458
This is such an edge case I don't think that's a huge problem, but I thought it worth mentioning.
Yeah — it makes sense, but could be surprising. It remains non-truncated everywhere except when it's being passed to the bootstrap. It's a shame that the pre-bootstrap phase of the agent running a job can't (AFAIK) easily send log output to the UI. I briefly considered passing the truncation info via yet another env var to the bootstrap, like we do for e.g. Lines 416 to 455 in e99cae5
Lines 437 to 450 in e99cae5
But I really don't want to add more environment vars, especially having just witnessed the shared env limits of some platforms (macOS being the most worrying with 256 KiB shared by all environment & argv). We could also truncate it server-side on the way in, before storing it. That would also relieve us of having to store enormous values. But I figured it'd be nice to instead truncate to a per-system-discovered env limit in the agent itself. That was before I found how hard it is to determine the maximum reasonable size for an environment variable. I think even if we eventually do that (server-side truncation), this patch should remain in the agent. |
BTW in case you didn't notice it, the “Buildkite environment variables” collapsed part of your build log does include a dump of the post-truncation env, including this line:
But, that's pretty hidden, doesn't directly indicate where it was truncated, and probably only appears if you're running the agent in debug mode? But 🤷♂️ |
Truncate the
BUILDKITE_MESSAGE
commit message passed to the bootstrap process to 64 KiB so that large commit messages won't stop execution.Follow-up to #1302, which enabled large commit messages to be pushed from the agent to Buildkite via
buildkite-agent meta-data set buildkite:git:commit
, but which uncovered this other bottleneck for message size.The 64 KiB figure was chosen somewhat arbitrarily; but it is…
Here's some ENV limits I've researched/discovered (see notes below):
A truncation marker is added to the end of the message like this:
And also logged to the agent:
I considered finding and re-embedding any
[skip ci]
/[ci skip]
markers, but then realised that would be silly; they prevent the build getting this far.Investigation into auto-discovering environment limit:
But this doesn't work for Windows.
A program to brute-force bisect to discover largest permitted env size:
Linux:
macOS:
Windows:
16,777,190
(16 MiB!)