actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.36k stars 1.16k forks source link

`actions/cache` is extremely slow running in Node 20 #1314

Closed chirag-droid closed 5 months ago

chirag-droid commented 5 months ago

Here is snippet of my custom action.

import * as core from '@actions/core'
import * as cache from '@actions/cache'
import * as exec from '@actions/exec'

import config from './config'

async function run(): Promise<void> {
  try {
    // Show ccache statistics (hits and stuff)
    await exec.exec('ccache -s')

    // Save cache using key
    core.info(`Save cache using ${config.cacheKey}`)
    await cache.saveCache([config.cache_dir], config.cacheKey)
  } catch (error: any) {
    // Show fail error if there is any error
    core.error(error)
    core.setFailed(error.message)
  }
}

run()

This always finishes in about ~2m11s no matter the OS or cache size.

Here is a debug log from a project using this action. The cache saved message comes up at almost instantly but the action doesn't exit until ~2m11s.

https://github.com/chirag-droid/Render3d/actions/runs/7684436720/job/20962442772

Cache saved successfully
##[debug]Node Action run completed with exit code 0
##[debug]Finishing: Post Setup ccache
chirag-droid commented 5 months ago

I don't know if this has anything to do with @actions/cache but any help would be appreciated. Its unusual that my post run action completes in ~2m11s

chirag-droid commented 5 months ago

I tracked down the pr that caused this. #1284

And looked in the source code, basically you have to manually do process.exit(0). I think many actions using @actions/cache are affected.

lazka commented 5 months ago

See https://github.com/actions/toolkit/issues/1578

Note that this repo does not contain the '@actions/cache' package, it's part of https://github.com/actions/toolkit

chirag-droid commented 5 months ago

Thanks for pointing it out.

actions/toolkit seems unresponsive about issues and prs. I have opened an issue there too

rfay commented 5 months ago

If this issue was not actually related to actions/cache, please close it @chirag-droid, thanks.

JCMais commented 5 months ago

while this issue is closed, it seems a workaround is easy to do (process.exit(0)), could this be added to actions./cache?

chirag-droid commented 4 months ago

while this issue is closed, it seems a workaround is easy to do (process.exit(0)), could this be added to actions./cache?

No they need to fix the internal problem or nodejs need to fix it.

the workaround can be applied in your own script