Nginx React App on Google Cloud Run does not start and ready condition status changes to false

Viewed 262

I have a react app deployed on cloud run with nginx as the webserver. For the setup I followed the guide here The docker set up runs perfectly fine on the local but it errors out on cloud run.

enter image description here

Here's the dockerfile and nginx config.

Dockerfile

# Name the node stage "builder"
FROM node:18-alpine AS builder

# Set working directory
WORKDIR /app

# Copy our node module specification
COPY package.json package.json
COPY yarn.lock yarn.lock

# install node modules and build assets
RUN yarn install --production

# Copy all files from current directory to working dir in image
# Except the one defined in '.dockerignore'
COPY . .

# Create production build of React App
RUN yarn build

# Choose NGINX as our base Docker image
FROM nginx:alpine

# Copy our nginx configuration
COPY nginx.conf /etc/nginx/conf.d/configfile.template
COPY ./environments/.env.final /usr/share/nginx/html/.env

RUN apk add --update nodejs
RUN apk add --update npm
RUN npm install -g runtime-env-cra@0.2.4

# Set working directory to nginx asset directory
WORKDIR /usr/share/nginx/html

# Remove default nginx static assets
RUN rm -rf *

# Copy static assets from builder stage
COPY --from=builder /app/build .

# Define environment variables for Cloud Run
ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
# Substitute $PORT variable in config file with the one passed via "docker run"
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && runtime-env-cra  && nginx -g 'daemon off;' && lsof -i:8080"

Nginx.conf

    server {
     # $PORT will be provided by 'docker run'
     listen       $PORT;
     server_name  localhost;
     error_log  /var/log/nginx/error.log debug;
     location / {
         root   /usr/share/nginx/html;
         index  index.html index.htm;
         try_files $uri /index.html;
     }

     gzip on;
     gzip_vary on;
     gzip_min_length 10240;
     gzip_proxied expired no-cache no-store private auth;
     gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
     gzip_disable "MSIE [1-6]\.";
}

To get more debugging information related to nginx I then used nginx-debug instead of nginx to run my app. Here are the logs. It's in reverse order. The bottom most log is the first log.

2022/04/30 04:51:48 [debug] 22#22: accept() not ready (11: Resource temporarily unavailable),2022-04-30T04:51:48.569382Z,
"2022/04/30 04:51:48 [debug] 21#21: *5 free: 00007FADEA046AE0, unused: 136",2022-04-30T04:51:48.569377Z,
2022/04/30 04:51:48 [debug] 21#21: *5 free: 00007FADEA03F570,2022-04-30T04:51:48.569372Z,
2022/04/30 04:51:48 [debug] 21#21: *5 reusable connection: 0,2022-04-30T04:51:48.569368Z,
2022/04/30 04:51:48 [debug] 21#21: *5 event timer del: 13: 62382,2022-04-30T04:51:48.569362Z,
2022/04/30 04:51:48 [debug] 21#21: *5 close http connection: 13,2022-04-30T04:51:48.569358Z,
"2022/04/30 04:51:48 [info] 21#21: *5 client closed connection while waiting for request, client: 169.254.1.1, server: 0.0.0.0:8080",2022-04-30T04:51:48.569352Z,
2022/04/30 04:51:48 [debug] 21#21: *5 recv: fd:13 0 of 1024,2022-04-30T04:51:48.569347Z,
"2022/04/30 04:51:48 [debug] 21#21: *5 recv: eof:1, avail:-1",2022-04-30T04:51:48.569342Z,
2022/04/30 04:51:48 [debug] 21#21: *5 malloc: 00007FADEA03F570:1024,2022-04-30T04:51:48.569338Z,
2022/04/30 04:51:48 [debug] 21#21: *5 http wait request handler,2022-04-30T04:51:48.569332Z,
"2022/04/30 04:51:48 [debug] 21#21: *4 free: 00007FADEA046D50, unused: 136",2022-04-30T04:51:48.569327Z,
2022/04/30 04:51:48 [debug] 21#21: *4 free: 00007FADEA03FAE0,2022-04-30T04:51:48.569322Z,
2022/04/30 04:51:48 [debug] 21#21: *4 reusable connection: 0,2022-04-30T04:51:48.569316Z,
2022/04/30 04:51:48 [debug] 21#21: *4 event timer del: 12: 62382,2022-04-30T04:51:48.569312Z,
2022/04/30 04:51:48 [debug] 21#21: *4 close http connection: 12,2022-04-30T04:51:48.569307Z,
"2022/04/30 04:51:48 [info] 21#21: *4 client closed connection while waiting for request, client: 169.254.1.1, server: 0.0.0.0:8080",2022-04-30T04:51:48.569302Z,
2022/04/30 04:51:48 [debug] 21#21: *4 recv: fd:12 0 of 1024,2022-04-30T04:51:48.569296Z,
"2022/04/30 04:51:48 [debug] 21#21: *4 recv: eof:1, avail:-1",2022-04-30T04:51:48.569291Z,
2022/04/30 04:51:48 [debug] 21#21: *4 malloc: 00007FADEA03FAE0:1024,2022-04-30T04:51:48.569286Z,
2022/04/30 04:51:48 [debug] 21#21: *4 http wait request handler,2022-04-30T04:51:48.569281Z,
2022/04/30 04:51:48 [debug] 21#21: *5 epoll add event: fd:13 op:1 ev:80002001,2022-04-30T04:51:48.569276Z,
2022/04/30 04:51:48 [debug] 21#21: *5 reusable connection: 1,2022-04-30T04:51:48.569270Z,
2022/04/30 04:51:48 [debug] 21#21: *5 event timer add: 13: 60000:62382,2022-04-30T04:51:48.569265Z,
2022/04/30 04:51:48 [debug] 21#21: *5 accept: 169.254.1.1:61453 fd:13,2022-04-30T04:51:48.569260Z,
2022/04/30 04:51:48 [debug] 21#21: posix_memalign: 00007FADEA046AE0:512 @16,2022-04-30T04:51:48.569255Z,
"2022/04/30 04:51:48 [debug] 21#21: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.569248Z,
2022/04/30 04:51:48 [debug] 21#21: *4 epoll add event: fd:12 op:1 ev:80002001,2022-04-30T04:51:48.569244Z,
2022/04/30 04:51:48 [debug] 21#21: *4 reusable connection: 1,2022-04-30T04:51:48.569239Z,
2022/04/30 04:51:48 [debug] 21#21: *4 event timer add: 12: 60000:62382,2022-04-30T04:51:48.569233Z,
2022/04/30 04:51:48 [debug] 21#21: *4 accept: 169.254.1.1:56829 fd:12,2022-04-30T04:51:48.569228Z,
2022/04/30 04:51:48 [debug] 21#21: posix_memalign: 00007FADEA046D50:512 @16,2022-04-30T04:51:48.569222Z,
"2022/04/30 04:51:48 [debug] 21#21: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.569216Z,
"2022/04/30 04:51:48 [debug] 22#22: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.569196Z,
"2022/04/30 04:51:48 [debug] 21#21: *3 free: 00007FADEA046AD0, unused: 136",2022-04-30T04:51:48.494728Z,
2022/04/30 04:51:48 [debug] 21#21: *3 free: 00007FADEA03F560,2022-04-30T04:51:48.494720Z,
2022/04/30 04:51:48 [debug] 21#21: *3 reusable connection: 0,2022-04-30T04:51:48.494714Z,
2022/04/30 04:51:48 [debug] 21#21: *3 event timer del: 12: 62307,2022-04-30T04:51:48.494708Z,
2022/04/30 04:51:48 [debug] 21#21: *3 close http connection: 12,2022-04-30T04:51:48.494701Z,
"2022/04/30 04:51:48 [info] 21#21: *3 client closed connection while waiting for request, client: 169.254.1.1, server: 0.0.0.0:8080",2022-04-30T04:51:48.494691Z,
2022/04/30 04:51:48 [debug] 21#21: *3 recv: fd:12 0 of 1024,2022-04-30T04:51:48.494682Z,
"2022/04/30 04:51:48 [debug] 21#21: *3 recv: eof:1, avail:-1",2022-04-30T04:51:48.494673Z,
2022/04/30 04:51:48 [debug] 21#21: *3 malloc: 00007FADEA03F560:1024,2022-04-30T04:51:48.494665Z,
2022/04/30 04:51:48 [debug] 21#21: *3 http wait request handler,2022-04-30T04:51:48.494657Z,
2022/04/30 04:51:48 [debug] 21#21: epoll add event: fd:7 op:1 ev:10000001,2022-04-30T04:51:48.494648Z,
2022/04/30 04:51:48 [debug] 21#21: epoll del event: fd:7 op:2 ev:00000000,2022-04-30T04:51:48.494634Z,
2022/04/30 04:51:48 [debug] 21#21: *3 epoll add event: fd:12 op:1 ev:80002001,2022-04-30T04:51:48.494625Z,
2022/04/30 04:51:48 [debug] 21#21: *3 reusable connection: 1,2022-04-30T04:51:48.494613Z,
2022/04/30 04:51:48 [debug] 21#21: *3 event timer add: 12: 60000:62307,2022-04-30T04:51:48.494603Z,
2022/04/30 04:51:48 [debug] 21#21: *3 accept: 169.254.1.1:50168 fd:12,2022-04-30T04:51:48.494593Z,
2022/04/30 04:51:48 [debug] 21#21: posix_memalign: 00007FADEA046AD0:512 @16,2022-04-30T04:51:48.494562Z,
"2022/04/30 04:51:48 [debug] 21#21: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.494539Z,
"2022/04/30 04:51:48 [debug] 22#22: *2 free: 00007FADEA046D50, unused: 136",2022-04-30T04:51:48.491920Z,
2022/04/30 04:51:48 [debug] 22#22: *2 free: 00007FADEA03FAE0,2022-04-30T04:51:48.491915Z,
2022/04/30 04:51:48 [debug] 22#22: *2 reusable connection: 0,2022-04-30T04:51:48.491909Z,
2022/04/30 04:51:48 [debug] 22#22: *2 event timer del: 8: 62304,2022-04-30T04:51:48.491904Z,
2022/04/30 04:51:48 [debug] 22#22: *2 close http connection: 8,2022-04-30T04:51:48.491899Z,
"2022/04/30 04:51:48 [info] 22#22: *2 client closed connection while waiting for request, client: 169.254.1.1, server: 0.0.0.0:8080",2022-04-30T04:51:48.491893Z,
2022/04/30 04:51:48 [debug] 22#22: *2 recv: fd:8 0 of 1024,2022-04-30T04:51:48.491886Z,
"2022/04/30 04:51:48 [debug] 22#22: *2 recv: eof:1, avail:-1",2022-04-30T04:51:48.491881Z,
2022/04/30 04:51:48 [debug] 22#22: *2 malloc: 00007FADEA03FAE0:1024,2022-04-30T04:51:48.491876Z,
2022/04/30 04:51:48 [debug] 22#22: *2 http wait request handler,2022-04-30T04:51:48.491869Z,
2022/04/30 04:51:48 [debug] 22#22: *2 epoll add event: fd:8 op:1 ev:80002001,2022-04-30T04:51:48.491864Z,
2022/04/30 04:51:48 [debug] 22#22: *2 reusable connection: 1,2022-04-30T04:51:48.491859Z,
2022/04/30 04:51:48 [debug] 22#22: *2 event timer add: 8: 60000:62304,2022-04-30T04:51:48.491854Z,
2022/04/30 04:51:48 [debug] 22#22: *2 accept: 169.254.1.1:18005 fd:8,2022-04-30T04:51:48.491849Z,
2022/04/30 04:51:48 [debug] 22#22: posix_memalign: 00007FADEA046D50:512 @16,2022-04-30T04:51:48.491844Z,
"2022/04/30 04:51:48 [debug] 22#22: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.491839Z,
"2022/04/30 04:51:48 [debug] 22#22: *1 free: 00007FADEA046AD0, unused: 136",2022-04-30T04:51:48.491834Z,
2022/04/30 04:51:48 [debug] 22#22: *1 free: 00007FADEA03F560,2022-04-30T04:51:48.491828Z,
2022/04/30 04:51:48 [debug] 22#22: *1 reusable connection: 0,2022-04-30T04:51:48.491820Z,
2022/04/30 04:51:48 [debug] 22#22: *1 event timer del: 8: 62304,2022-04-30T04:51:48.491813Z,
2022/04/30 04:51:48 [debug] 22#22: *1 close http connection: 8,2022-04-30T04:51:48.491805Z,
"2022/04/30 04:51:48 [info] 22#22: *1 client closed connection while waiting for request, client: 169.254.1.1, server: 0.0.0.0:8080",2022-04-30T04:51:48.491798Z,
2022/04/30 04:51:48 [debug] 22#22: *1 recv: fd:8 0 of 1024,2022-04-30T04:51:48.491791Z,
"2022/04/30 04:51:48 [debug] 22#22: *1 recv: eof:1, avail:-1",2022-04-30T04:51:48.491783Z,
2022/04/30 04:51:48 [debug] 22#22: *1 malloc: 00007FADEA03F560:1024,2022-04-30T04:51:48.491776Z,
2022/04/30 04:51:48 [debug] 22#22: *1 http wait request handler,2022-04-30T04:51:48.491754Z,
2022/04/30 04:51:48 [debug] 22#22: epoll add event: fd:7 op:1 ev:10000001,2022-04-30T04:51:48.491746Z,
2022/04/30 04:51:48 [debug] 22#22: epoll del event: fd:7 op:2 ev:00000000,2022-04-30T04:51:48.491740Z,
2022/04/30 04:51:48 [debug] 22#22: *1 epoll add event: fd:8 op:1 ev:80002001,2022-04-30T04:51:48.491733Z,
2022/04/30 04:51:48 [debug] 22#22: *1 reusable connection: 1,2022-04-30T04:51:48.491725Z,
2022/04/30 04:51:48 [debug] 22#22: *1 event timer add: 8: 60000:62304,2022-04-30T04:51:48.491718Z,
2022/04/30 04:51:48 [debug] 22#22: *1 accept: 169.254.1.1:31598 fd:8,2022-04-30T04:51:48.491711Z,
2022/04/30 04:51:48 [debug] 22#22: posix_memalign: 00007FADEA046AD0:512 @16,2022-04-30T04:51:48.491703Z,
"2022/04/30 04:51:48 [debug] 22#22: accept on 0.0.0.0:8080, ready: 0",2022-04-30T04:51:48.491682Z,
2022/04/30 04:51:48 [debug] 22#22: epoll add event: fd:7 op:1 ev:10000001,2022-04-30T04:51:48.486691Z,
2022/04/30 04:51:48 [debug] 21#21: epoll add event: fd:7 op:1 ev:10000001,2022-04-30T04:51:48.486669Z,
2022/04/30 04:51:48 [notice] 20#20: start worker process 22,2022-04-30T04:51:48.485982Z,
2022/04/30 04:51:48 [notice] 20#20: start worker process 21,2022-04-30T04:51:48.485857Z,
2022/04/30 04:51:48 [notice] 20#20: start worker processes,2022-04-30T04:51:48.485713Z,
2022/04/30 04:51:48 [notice] 20#20: getrlimit(RLIMIT_NOFILE): 1024:4096,2022-04-30T04:51:48.485662Z,
2022/04/30 04:51:48 [notice] 20#20: OS: Linux 5.8.9,2022-04-30T04:51:48.485656Z,
"2022/04/30 04:51:48 [notice] 20#20: built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027) ",2022-04-30T04:51:48.485635Z,
2022/04/30 04:51:48 [notice] 20#20: nginx/1.21.6,2022-04-30T04:51:48.485627Z,
"2022/04/30 04:51:48 [notice] 20#20: using the ""epoll"" event method",2022-04-30T04:51:48.485600Z,
"  ",2022-04-30T04:51:48.421815Z,
"  Thank you for using runtime-env-cra!",2022-04-30T04:51:48.421806Z,
,2022-04-30T04:51:48.421799Z,
"  Result: window.__RUNTIME_CONFIG__ = {"NODE_ENV":"integration"};",2022-04-30T04:51:48.421790Z,
Successfully generated your runtime-env config!,2022-04-30T04:51:48.421768Z,
"  ",2022-04-30T04:51:48.409129Z,
"  Your environment variables will be available on 'window.__RUNTIME_CONFIG__'",2022-04-30T04:51:48.409123Z,
,2022-04-30T04:51:48.409116Z,
"    --env-file = ./.env",2022-04-30T04:51:48.409111Z,
"    --config-name = ./runtime-env.js",2022-04-30T04:51:48.409105Z,
"  Provided flags:",2022-04-30T04:51:48.409096Z,

The gist here is that I keep getting client closed connection while waiting for request. Any pointers on how to fix this? I don't understand the reason why this is happening.

0 Answers
Related