Repository: next.js
Issue: Next.js application showcases intermittent slow responses, in Google Cloud Run instance running, from 30 seconds up to more than 1 minute
Labels: bug,Runtime,Pages Router

### Verify canary release

- [X] I verified that the issue exists in the latest Next.js canary release

### Provide environment information

```bash
Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 16.18.1
      npm: 8.19.2
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.3.0
      eslint-config-next: 12.3.0
      react: 18.2.0
      react-dom: 18.2.0
```


### Which area(s) of Next.js are affected? (leave empty if unsure)

Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)

### Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/eager-gagarin-9quspu?file=%2Fpages%2Fironsession.ts&selection=%5B%7B%22endColumn%22%3A20%2C%22endLineNumber%22%3A8%2C%22startColumn%22%3A20%2C%22startLineNumber%22%3A8%7D%5D

### To Reproduce

1. Deploy a Next.js application to Google Cloud Run.

2. Send requests to the application and observe the response time.

### Describe the Bug

I have a Next.js application running in a Google Cloud Run instance, and I'm experiencing intermittent slow responses. Sometimes the response time is around 30 seconds, but other times it can be more than 1 minute. This behaviour is not consistent and happens randomly.
Right now, the only known fact is that if traffic is constant, the instance is responding very quickly, but whenever the traffic is dropped, the issue resurfaces.

The problem never happens when executing the same Docker image from a local workstation.

I have reached out to Google Cloud support, and they have informed me that the latencies are originating from the code execution.

### Environment:
	•	Next.js version: 12.3.0
	•	Operating system:  node:16-alpine
	•	Deployment platform: Google Cloud Run

### Dockerfile:


```
# Install dependencies only when needed
FROM node:16-alpine AS deps

# Install Alpine packages
# To understand why libc6-compat might be needed, check:
# https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine
RUN apk add --no-cache libc6-compat

# Working directory
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json package-lock.json .
RUN npm ci

################################################################################
# Rebuild the source code only when needed
FROM node:16-alpine AS builder

# Working directory
WORKDIR /app

# Copy from dependencies prepared files
COPY --from=deps /app/node_modules ./node_modules

# Copy application files
COPY . .

# If using npm comment out above and use below instead
RUN npm run build

################################################################################
# Production image, copy all the files and run next
FROM node:16-alpine AS runner

# Image Build arguments
ARG GIT_HASH 'NA'
ARG GIT_BRANCH 'NA'

# Add system user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

# Copy from builder prepared files
# Public files
COPY --from=builder /app/public /app/public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone /app/
COPY --from=builder --chown=nextjs:nodejs /app/.next/static /app/.next/static

# User to run all commands as
USER nextjs

# Working directory
WORKDIR /app

# Environment variables
ENV NODE_ENV production
ENV PORT 3000
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry.
ENV NEXT_TELEMETRY_DISABLED 0
ENV BACKEND_URL https://api.example.com
ENV BROWSER none
ENV FAST_REFRESH true
# ... some other sensitive env vars here ...

# Exposed ports
EXPOSE 3000

# Container command
CMD ["node", "server.js"]

```

**Additional information:**
It's worth noting that I'm not doing any API requests in the backend of my Next.js application. I'm using Iron Session for authentication, as recommended in the Next.js documentation (link: https://nextjs.org/docs/authentication).

Any help or guidance on how to resolve this issue, debugging, or possible root causes would be greatly appreciated. Thank you!


### Expected Behavior

The application should respond in a timely manner, with response times consistently under 10 seconds.

### Which browser are you using? (if relevant)

_No response_

### How are you deploying your application? (if relevant)

Google Cloud Run