1

We are periodically seeing builds fail within our cloud build process with the following error:

docker.io/library/node:14 npm ERR! cb() never called!

npm ERR! This is an error with npm itself. Please report this error at: npm ERR! https://npm.community

Steps from build configuration:

steps:
  - name: 'gcr.io/cloud-builders/git'
    id: 'fetch'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        # convert the shallow clone to regular one
        git fetch --unshallow --no-tags
    waitFor: ['-']

  - name: 'node:14'
    id: 'npm-install'
    entrypoint: 'bash'
    args:
      - '-c'
      - |
        npm ci --unsafe-perm
    env:
      - 'CYPRESS_INSTALL_BINARY=0'
      - 'CYPRESS_CACHE_FOLDER=/cypress_cache'
    waitFor: ['fetch']

Any thoughts on things to try or to remediate this issue?

EDIT: All packages are installed from npm.

Jesse
  • 8,223
  • 6
  • 49
  • 81
  • What hosts the npm registry, from where the packages are installed? – Milan Tenk Sep 23 '21 at 17:51
  • Does this happen only occasionally? Are your npm and Node versions compatible? This is old but may be useful: https://stackoverflow.com/questions/15393821/npm-err-cb-never-called?rq=1 – Javier A Sep 24 '21 at 12:29
  • @MilanTenk all packages are from npmjs. – Jesse Sep 25 '21 at 15:05
  • @JavierA it happens only occasionally. Yes node / npm version are compatabile as this is the official node:14 docker container – Jesse Sep 25 '21 at 15:05
  • Isn't there maybe a company proxy or policy, that somehow sporadically blocks the downloading of a package? – Milan Tenk Sep 25 '21 at 15:54
  • @MilanTenk Shouldn't be proxy related. Fresh vm, fresh image and crashes maybe 1 in 20 times? – Jesse Sep 27 '21 at 00:19
  • I had a very similar issue in a company environment. In my case it was actually reproducable on developer PC-s as well, if all the cache-es were properly cleaned. (All the cache-es cleaned means in this context followning: https://stackoverflow.com/questions/69310464/npm-install-always-uses-artifactory-registry-and-ignores-npmrc-file/69324487#69324487). After a lot of meetings with different supports we actually did not make it, to fix the issue, as a workaround we built in a retry logic: if the `npm install` fails, try it again. This was stable enough. – Milan Tenk Sep 27 '21 at 16:14
  • Are you still experiencing the same issue? Did you try the @MilanTenk approach? It seems a good idea. – drauedo Oct 08 '21 at 07:53
  • @drauedo no we haven't automatically built in a retry step. Essentially what we are doing is manually restarting the build when this happens. – Jesse Oct 08 '21 at 16:56

2 Answers2

1

As suggested by @Milan Tenk a good approach would be to implement a retry logic in your build by wrapping your command in a bash script.

Here are some examples on how you can modify you yaml file to a run bash scripts in Cloud Build:

steps:
- name: 'bash'
  args: ['./retryPolicy.bash']

If bash is not the default entrypoint:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args: ['tools/retryPolicy.sh','--foo']

And here is an example of a retry logic implementation in bash:

#!/bin/bash
set -euo pipefail

function myFunction() {
    myCommand
    return $?
}

retry=0
maxRetries=5
retryInterval=15
until [ ${retry} -ge ${maxRetries} ]
do
    myFunction && break
    retry=$[${retry}+1]
    echo "Retrying [${retry}/${maxRetries}] in ${retryInterval}(s) "
    sleep ${retryInterval}
done

if [ ${retry} -ge ${maxRetries} ]; then
  echo "Failed after ${maxRetries} attempts!"
  exit 1
fi

Please let me know if that approach worked for you.

drauedo
  • 641
  • 4
  • 17
0

See NPM CLI WiKi: https://github.com/npm/cli/wiki/%22cb()-never-called%3F-Exit-handler-never-called%3F-I'm-having-the-same-problem!%22

Sadly, there's never a straightforward answer.

However, many people seem to suggest deleting the node_modules folder in your project and also running the command npm cache clean -force.

For me it did not work - so I copied a node_modules folder from a PC, which could run npm install without having the error. This at least allowed to use npm install without errors and build the project again.

R. Hoek
  • 916
  • 8
  • 27