Skip to content

Bsdtar + zstd fallback to prevent zstd hanging issue on windows#1237

Merged
Phantsure merged 24 commits intoreleases/cache-v3-betafrom
pdotl/win-bsdtar-zstd
Dec 1, 2022
Merged

Bsdtar + zstd fallback to prevent zstd hanging issue on windows#1237
Phantsure merged 24 commits intoreleases/cache-v3-betafrom
pdotl/win-bsdtar-zstd

Conversation

@lvpx
Copy link
Contributor

@lvpx lvpx commented Nov 16, 2022

This PR implements the bsdtar + zstd fallback for windows to prevent the bsdtar + zstd hanging on windows issue highlighted in #301

Context and Motivation

bsdtar on windows runners tends to hang when called with --use-compress-program zstd. During testing we found the issue can be circumvented by calling bsdtar and zstd as separate processes such as tar [OPTIONS] && zstd [OPTIONS]. If tar fails then zstd won't run.

For compression, command would be similar to tar [OPTIONS] && zstd [OPTIONS] and for decompression, command would be similar to zstd -d [OPTIONS] && tar [OPTIONS].

This PR implements this approach as a fallback method since from #1239 gnutar will be default on windows where this problem does not exist.

Requesting Feedback

The ordering of arguments while forming the tar command 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

@Phantsure Phantsure changed the base branch from main to releases/cache-v3-beta November 17, 2022 08:21
@lvpx lvpx marked this pull request as ready for review November 17, 2022 09:21
@lvpx lvpx requested a review from a team as a code owner November 17, 2022 09:21
@lvpx lvpx requested a review from bishal-pdMSFT November 17, 2022 09:22
@lvpx lvpx changed the title Bsdtar + zstd fallback to prevent zstd hanging issue on windows [WIP] Bsdtar + zstd fallback to prevent zstd hanging issue on windows Nov 17, 2022
Comment on lines +170 to +171
...(await getCompressionProgram()),
cacheFileName.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally it shouldn't affect. In windows case due to pipe symbol it is needed. I would take a look at it

function getCompressionProgram(): string[] {
async function getCompressionProgram(): Promise<string[]> {
const tarPath = await getTarPath([])
const BSD_TAR_ZSTD = IS_WINDOWS && tarPath === SystemTarPathOnWindows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

switch (compressionMethod) {
case CompressionMethod.Zstd:
if (BSD_TAR_ZSTD) {
return ['-a'] // auto-detect compression
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will auto-detection take care of --long=30 part?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

// 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([])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Create a separate function to just get tar path
  2. Or move settings the args to getCompressionProgram where anyways we are setting more arguments

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args set in getTarPath are only the ones related to particular os which also helps in deciding which tar to use.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we can break into two function - one to get tar path and another to to get archive command.

@bishal-pdMSFT
Copy link
Contributor

@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)?

  1. Decide tar and its path
  2. For that tar decide compression
  3. A map for create/extract command which has three pivots - tar, compression and OS.

@Phantsure Phantsure self-assigned this Nov 21, 2022
@Phantsure
Copy link
Contributor

I agree with you how the logic is spread at different places.

A map for create/extract command which has three pivots - tar, compression and OS.

@pdotl also pointed this out. Let me try to work on reducing the number of pivots.

@Phantsure Phantsure marked this pull request as draft November 22, 2022 10:58
@Phantsure Phantsure force-pushed the pdotl/win-bsdtar-zstd branch from c5abe60 to 2163245 Compare November 23, 2022 10:51
@Phantsure Phantsure force-pushed the pdotl/win-bsdtar-zstd branch from 2163245 to 1f33717 Compare November 23, 2022 11:20
@Phantsure Phantsure marked this pull request as ready for review November 23, 2022 11:52
@Phantsure Phantsure changed the title [WIP] Bsdtar + zstd fallback to prevent zstd hanging issue on windows Bsdtar + zstd fallback to prevent zstd hanging issue on windows Nov 23, 2022
@Phantsure Phantsure force-pushed the pdotl/win-bsdtar-zstd branch from e4ce959 to 98fe6a2 Compare November 30, 2022 10:17
@Phantsure Phantsure force-pushed the pdotl/win-bsdtar-zstd branch from 98fe6a2 to 8595831 Compare November 30, 2022 10:37
@Phantsure Phantsure merged commit 785599d into releases/cache-v3-beta Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants