vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.2k stars 27.02k forks source link

Memory Leak with Image Optimization in Next.js Docker Environment #66103

Open adgsenpai opened 6 months ago

adgsenpai commented 6 months ago

Link to the code that reproduces this issue

https://github.com/adgsenpai/imageleakdemo

To Reproduce

  1. Create a Dockerfile for the Next.js application:
    
    FROM node:21.1.0-alpine

WORKDIR /app

COPY package*.json ./ RUN npm install

COPY . .

RUN npm run build

EXPOSE 3000

CMD ["npm", "start"]


2. Build the image

docker build -t nextjs-app .


3. Run the docker container

docker run -p 3000:3000 nextjs-app


4. Access the application and observe the memory usage.

5. Enable image optimization by adding or ensuring the following in `next.config.js`:

module.exports = { images: { domains: ['your-domain.com'], }, };


6. Monitor the memory usage using Docker stats or any monitoring tool:

docker stats


### Current vs. Expected behavior

Expected Behavior:
The Next.js application should run without any significant memory leaks, maintaining stable memory usage during operation.

Actual Behavior:
The application shows progressively increasing memory usage over time, leading to high memory consumption and potential crashes.

### Provide environment information

```bash
Operating System:
      Platform: linux
      Arch: x64
      Version: Alpine Linux
    Binaries:
      Node: 20.11.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.1.6
      react: 17.0.2
      react-dom: 17.0.2

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

Deployment Platform: Docker Reproducibility: The issue is consistently reproducible in the Docker environment. It does not occur when running the application locally outside of Docker. Browsers: The memory leak is observed regardless of the browser used to access the application, indicating it is not browser-specific. Environment: The issue has been specifically noted when running on Alpine Linux with the following setup: Platform: linux Arch: x64 Version: Alpine Linux

vitalyiegorov commented 5 months ago

facing the same issue on 14.2.1

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

jonsoku-dev commented 1 month ago

nextjs is a really great framework but it's really tricky to use if it's not vercel..