Bsdtar + zstd fallback to prevent zstd hanging issue on windows#1237
Bsdtar + zstd fallback to prevent zstd hanging issue on windows#1237Phantsure merged 24 commits intoreleases/cache-v3-betafrom
Conversation
packages/cache/src/internal/tar.ts
Outdated
| ...(await getCompressionProgram()), | ||
| cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/') |
There was a problem hiding this comment.
Does moving this args order have any negative effect on gnutar case or bsdtar on macos case? Essentially it would be good to idea to test all these existing scenarios for regression.
There was a problem hiding this comment.
Generally it shouldn't affect. In windows case due to pipe symbol it is needed. I would take a look at it
packages/cache/src/internal/tar.ts
Outdated
| function getCompressionProgram(): string[] { | ||
| async function getCompressionProgram(): Promise<string[]> { | ||
| const tarPath = await getTarPath([]) | ||
| const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows |
There was a problem hiding this comment.
Naming it BSD_TAR_WINDOWS may be better as it coveys that this applies only for windows and uses bsdtar. zstd is already evident from switch case below.
packages/cache/src/internal/tar.ts
Outdated
| switch (compressionMethod) { | ||
| case CompressionMethod.Zstd: | ||
| if (BSD_TAR_ZSTD) { | ||
| return ['-a'] // auto-detect compression |
There was a problem hiding this comment.
Will auto-detection take care of --long=30 part?
There was a problem hiding this comment.
It seems to be used for compression where information is taken from tar file extension. So I think it can't take care of that
packages/cache/src/internal/tar.ts
Outdated
| // unzstd is equivalent to 'zstd -d' | ||
| // --long=#: Enables long distance matching with # bits. Maximum is 30 (1GB) on 32-bit OS and 31 (2GB) on 64-bit. | ||
| // Using 30 here because we also support 32-bit self-hosted runners. | ||
| const tarPath = await getTarPath([]) |
There was a problem hiding this comment.
getTarPath is only used for getting to know if SystemTarPathOnWindows is used or not. This can be simplified so that we do not need to fit args array.
For example either:
- Create a separate function to just get tar path
- Or move settings the args to
getCompressionProgramwhere anyways we are setting more arguments
There was a problem hiding this comment.
args set in getTarPath are only the ones related to particular os which also helps in deciding which tar to use.
There was a problem hiding this comment.
In that case we can break into two function - one to get tar path and another to to get archive command.
|
@Phantsure @pdotl overall I feel that the logic to find right command for various combinations is very spread-out and hence difficult to maintain. Should we think about simplifying it (in this or a separate PR)?
|
|
I agree with you how the logic is spread at different places.
@pdotl also pointed this out. Let me try to work on reducing the number of pivots. |
c5abe60 to
2163245
Compare
2163245 to
1f33717
Compare
e4ce959 to
98fe6a2
Compare
98fe6a2 to
8595831
Compare
This PR implements the
bsdtar + zstdfallback for windows to prevent thebsdtar + zstdhanging on windows issue highlighted in #301Context and Motivation
bsdtaron windows runners tends to hang when called with--use-compress-program zstd. During testing we found the issue can be circumvented by callingbsdtarandzstdas separate processes such astar [OPTIONS] && zstd [OPTIONS]. Iftarfails thenzstdwon't run.For compression, command would be similar to
tar [OPTIONS] && zstd [OPTIONS]and for decompression, command would be similar tozstd -d [OPTIONS] && tar [OPTIONS].This PR implements this approach as a fallback method since from #1239
gnutarwill be default on windows where this problem does not exist.Requesting Feedback
The ordering of arguments while forming the
tarcommand that executes the archiving and compression is what has changed, so the change has larger exposure than required. Feel free to suggest better ways to implement this fallback where the impact can be minimized.Relevant Documentation