Npm ERR! code ERR_SOCKET_TIMEOUT when building mfe image

Hi there! I’ve been trying to build the mfe images using tutor nightly but keep getting this error:

[+] Building 40.3s (95/127)                                                                                                                                                                                        
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                               0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 18.00kB                                                                                                                                                                       0.0s
 => [internal] load metadata for docker.io/library/caddy:2.6.3                                                                                                                                                0.0s
 => [internal] load metadata for docker.io/library/node:16.14-bullseye-slim                                                                                                                                   0.7s
 => [auth] library/node:pull token for registry-1.docker.io                                                                                                                                                   0.0s
 => [production  1/10] FROM docker.io/library/caddy:2.6.3                                                                                                                                                     0.0s
 => [base 1/4] FROM docker.io/library/node:16.14-bullseye-slim@sha256:d54981fe891c9e3442ea05cb668bc8a2a3ee38609ecce52c7b5a609fadc6f64b                                                                        0.0s
 => [internal] load build context                                                                                                                                                                             0.0s
 => => transferring context: 64B                                                                                                                                                                              0.0s
 => CACHED [production  2/10] RUN mkdir -p /openedx/dist                                                                                                                                                      0.0s
 => CACHED [authn-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                                0.0s
 => CACHED [communications-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                       0.0s
 => CACHED [base 2/4] RUN apt update   && apt install -y git     gcc libgl1 libxi6 make     autoconf libtool pkg-config zlib1g-dev     python g++     libpng-dev                                              0.0s
 => CACHED [base 3/4] RUN mkdir -p /openedx/app /openedx/env                                                                                                                                                  0.0s
 => CACHED [base 4/4] WORKDIR /openedx/app                                                                                                                                                                    0.0s
 => CACHED [authn-src 1/2] RUN git clone https://github.com/openedx/frontend-app-authn --branch master --depth 1 .                                                                                            0.0s
 => CACHED [authn-common 1/6] COPY --from=authn-src /openedx/app/package.json /openedx/app/package.json                                                                                                       0.0s
 => CACHED [authn-common 2/6] COPY --from=authn-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                             0.0s
 => CACHED [authn-common 3/6] RUN npm config set timeout 6000000                                                                                                                                              0.0s
 => CACHED [communications-common 1/6] COPY --from=communications-src /openedx/app/package.json /openedx/app/package.json                                                                                     0.0s
 => CACHED [communications-common 2/6] COPY --from=communications-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                           0.0s
 => CACHED [communications-common 3/6] RUN npm config set timeout 6000000                                                                                                                                     0.0s
 => CACHED [communications-src 1/2] RUN git clone https://github.com/openedx/frontend-app-communications --branch master --depth 1 .                                                                          0.0s
 => CACHED [profile-src 1/2] RUN git clone https://github.com/openedx/frontend-app-profile --branch master --depth 1 .                                                                                        0.0s
 => CACHED [profile-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                              0.0s
 => CACHED [profile-common 1/6] COPY --from=profile-src /openedx/app/package.json /openedx/app/package.json                                                                                                   0.0s
 => CACHED [profile-common 2/6] COPY --from=profile-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                         0.0s
 => CACHED [profile-common 3/6] RUN npm config set timeout 6000000                                                                                                                                            0.0s
 => CACHED [learning-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                             0.0s
 => CACHED [gradebook-src 1/2] RUN git clone https://github.com/openedx/frontend-app-gradebook --branch master --depth 1 .                                                                                    0.0s
 => CACHED [gradebook-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                            0.0s
 => CACHED [discussions-src 1/2] RUN git clone https://github.com/openedx/frontend-app-discussions --branch master --depth 1 .                                                                                0.0s
 => CACHED [discussions-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                          0.0s
 => CACHED [course-authoring-src 1/2] RUN git clone https://github.com/openedx/frontend-app-course-authoring --branch master --depth 1 .                                                                      0.0s
 => CACHED [course-authoring-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                     0.0s
 => CACHED [learning-src 1/2] RUN git clone https://github.com/openedx/frontend-app-learning --branch master --depth 1 .                                                                                      0.0s
 => CACHED [learning-common 1/6] COPY --from=learning-src /openedx/app/package.json /openedx/app/package.json                                                                                                 0.0s
 => CACHED [learning-common 2/6] COPY --from=learning-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                       0.0s
 => CACHED [learning-common 3/6] RUN npm config set timeout 6000000                                                                                                                                           0.0s
 => CACHED [discussions-common 1/6] COPY --from=discussions-src /openedx/app/package.json /openedx/app/package.json                                                                                           0.0s
 => CACHED [discussions-common 2/6] COPY --from=discussions-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                 0.0s
 => CACHED [discussions-common 3/6] RUN npm config set timeout 6000000                                                                                                                                        0.0s
 => CACHED [gradebook-common 1/6] COPY --from=gradebook-src /openedx/app/package.json /openedx/app/package.json                                                                                               0.0s
 => CACHED [gradebook-common 2/6] COPY --from=gradebook-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                     0.0s 
 => CACHED [gradebook-common 3/6] RUN npm config set timeout 6000000                                                                                                                                          0.0s 
 => CACHED [account-src 1/2] RUN git clone https://github.com/openedx/frontend-app-account --branch master --depth 1 .                                                                                        0.0s 
 => CACHED [account-src 2/2] RUN stat /openedx/app/src/i18n/messages 2> /dev/null || (echo "missing messages folder" && mkdir -p /openedx/app/src/i18n/messages)                                              0.0s 
 => CACHED [course-authoring-common 1/6] COPY --from=course-authoring-src /openedx/app/package.json /openedx/app/package.json                                                                                 0.0s 
 => CACHED [course-authoring-common 2/6] COPY --from=course-authoring-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                       0.0s 
 => CACHED [course-authoring-common 3/6] RUN npm config set timeout 6000000                                                                                                                                   0.0s
 => CACHED [account-common 1/6] COPY --from=account-src /openedx/app/package.json /openedx/app/package.json                                                                                                   0.0s
 => CACHED [account-common 2/6] COPY --from=account-src /openedx/app/package-lock.json /openedx/app/package-lock.json                                                                                         0.0s
 => CACHED [account-common 3/6] RUN npm config set timeout 6000000                                                                                                                                            0.0s
 => ERROR [communications-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                   37.9s
 => CANCELED [authn-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                         38.2s
 => CANCELED [profile-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                       39.5s
 => CANCELED [learning-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                      39.3s
 => CANCELED [discussions-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                   38.8s
 => CANCELED [course-authoring-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                              38.5s
 => CANCELED [gradebook-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                     39.1s
 => CANCELED [account-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm                                                                       38.3s
 => CACHED [account-i18n 1/4] COPY --from=account-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                           0.0s
 => CACHED [i18n 1/3] COPY ./i18n /openedx/i18n                                                                                                                                                               0.0s
 => CACHED [i18n 2/3] RUN chmod a+x /openedx/i18n/*.js                                                                                                                                                        0.0s
 => CACHED [i18n 3/3] RUN echo "copying i18n data"   && mkdir -p /openedx/i18n/communications   && mkdir -p /openedx/i18n/authn   && mkdir -p /openedx/i18n/account   && mkdir -p /openedx/i18n/course-autho  0.0s
 => CACHED [account-i18n 2/4] COPY --from=i18n /openedx/i18n/account /openedx/i18n/account                                                                                                                    0.0s
 => CACHED [account-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                        0.0s
 => CACHED [account-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/account /openedx/app/src/i18n/messages                                                             0.0s
 => CACHED [learning-i18n 1/4] COPY --from=learning-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                         0.0s
 => CACHED [learning-i18n 2/4] COPY --from=i18n /openedx/i18n/learning /openedx/i18n/learning                                                                                                                 0.0s
 => CACHED [learning-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                       0.0s
 => CACHED [learning-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/learning /openedx/app/src/i18n/messages                                                           0.0s
 => CACHED [course-authoring-i18n 1/4] COPY --from=course-authoring-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                         0.0s
 => CACHED [course-authoring-i18n 2/4] COPY --from=i18n /openedx/i18n/course-authoring /openedx/i18n/course-authoring                                                                                         0.0s
 => CACHED [course-authoring-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                               0.0s
 => CACHED [course-authoring-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/course-authoring /openedx/app/src/i18n/messages                                           0.0s
 => CACHED [profile-i18n 1/4] COPY --from=profile-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                           0.0s
 => CACHED [profile-i18n 2/4] COPY --from=i18n /openedx/i18n/profile /openedx/i18n/profile                                                                                                                    0.0s
 => CACHED [profile-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                        0.0s
 => CACHED [profile-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/profile /openedx/app/src/i18n/messages                                                             0.0s
 => CACHED [authn-i18n 1/4] COPY --from=authn-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                               0.0s
 => CACHED [authn-i18n 2/4] COPY --from=i18n /openedx/i18n/authn /openedx/i18n/authn                                                                                                                          0.0s
 => CACHED [authn-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                          0.0s
 => CACHED [authn-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/authn /openedx/app/src/i18n/messages                                                                 0.0s
 => CACHED [gradebook-i18n 1/4] COPY --from=gradebook-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                       0.0s
 => CACHED [gradebook-i18n 2/4] COPY --from=i18n /openedx/i18n/gradebook /openedx/i18n/gradebook                                                                                                              0.0s
 => CACHED [gradebook-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                      0.0s
 => CACHED [gradebook-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/gradebook /openedx/app/src/i18n/messages                                                         0.0s
 => CACHED [communications-i18n 1/4] COPY --from=communications-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                             0.0s
 => CACHED [communications-i18n 2/4] COPY --from=i18n /openedx/i18n/communications /openedx/i18n/communications                                                                                               0.0s
 => CACHED [communications-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                 0.0s
 => CACHED [communications-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/communications /openedx/app/src/i18n/messages                                               0.0s
 => CACHED [discussions-i18n 1/4] COPY --from=discussions-src /openedx/app/src/i18n/messages /openedx/app/src/i18n/messages                                                                                   0.0s
 => CACHED [discussions-i18n 2/4] COPY --from=i18n /openedx/i18n/discussions /openedx/i18n/discussions                                                                                                        0.0s
 => CACHED [discussions-i18n 3/4] COPY --from=i18n /openedx/i18n/i18n-merge.js /openedx/i18n/i18n-merge.js                                                                                                    0.0s
 => CACHED [discussions-i18n 4/4] RUN /openedx/i18n/i18n-merge.js /openedx/app/src/i18n/messages /openedx/i18n/discussions /openedx/app/src/i18n/messages                                                     0.0s
------
 > [communications-common 4/6] RUN npm clean-install --no-audit --no-fund --registry=https://registry.npmjs.org/   && rm -rf ~/.npm:
#0 25.75 npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
#0 37.64 npm notice 
#0 37.64 npm notice New major version of npm available! 8.5.0 -> 9.7.1
#0 37.64 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.7.1>
#0 37.64 npm notice Run `npm install -g npm@9.7.1` to update!
#0 37.64 npm notice 
#0 37.64 npm ERR! code ERR_SOCKET_TIMEOUT
#0 37.64 npm ERR! network Socket timeout
#0 37.64 npm ERR! network This is a problem related to network connectivity.
#0 37.64 npm ERR! network In most cases you are behind a proxy or have bad network settings.
#0 37.64 npm ERR! network 
#0 37.64 npm ERR! network If you are behind a proxy, please make sure that the
#0 37.64 npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
#0 37.67 
#0 37.67 npm ERR! A complete log of this run can be found in:
#0 37.67 npm ERR!     /root/.npm/_logs/2023-06-14T02_01_48_800Z-debug-0.log
------
Dockerfile:55
--------------------
  54 |     RUN npm config set timeout 6000000
  55 | >>> RUN npm clean-install --no-audit --no-fund --registry=$NPM_REGISTRY \
  56 | >>>   && rm -rf ~/.npm
  57 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c npm clean-install --no-audit --no-fund --registry=$NPM_REGISTRY   && rm -rf ~/.npm" did not complete successfully: exit code: 1

I’ve tried a few things:
First I changed internet provider since I thought it was my internet connection but got no results. Then I increased the timeout npm config in the docker image --in two different ways:
First I tried RUN npm config set timeout 6000000 and then like this:

RUN npm config set fetch-retry-mintimeout 20000
RUN npm config set fetch-retry-maxtimeout 120000

Without success. I also created a container to check its memory limits, and it’s the same as the host machine. So I don’t think it’s a memory thing, I could be wrong though.

I know this has happened before, according to these posts:

None of the suggestions have worked for me. What do you folks think? Has this happened to you before?

This probably because of Docker is trying to install X MFEs at the same time, thus it migjt trigger network error, in my expirence usually this can be resovled either when upgrading npm version to latest, this would need to be done at the top of Dockerfile, or see @regis suggestion here Document how to use BuildKit options to reduce resources consumption · Issue #125 · overhangio/tutor-mfe · GitHub where it work by forcing Docker minizie the number of parrael jobs

In a day or so the nightly branch will receive the caching improvements that were introduced in the Palm branch, so hopefully these issues will resolve themselves…

I solved it doing this:

  • vim buildkit.toml
  • content:
 [worker.oci]
   max-parallelism = 2
  • docker buildx create --use --node=max2cpu --driver=docker-container --config=./buildkit.toml

Buildkit ref: Document how to use BuildKit options to reduce resources consumption · Issue #125 · overhangio/tutor-mfe · GitHub

Thanks folks! @ghassan @regis @jvente. I upgraded npm and it worked as well!