Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adgsenpai opened this issue May 23, 2024 · 7 comments
Closed

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

adgsenpai opened this issue May 23, 2024 · 7 comments
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked

Comments

@adgsenpai
Copy link

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"]

  1. Build the image
docker build -t nextjs-app .
  1. Run the docker container
docker run -p 3000:3000 nextjs-app
  1. Access the application and observe the memory usage.

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

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

  1. 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

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

@adgsenpai adgsenpai added the bug Issue was opened via the bug report template. label May 23, 2024
@github-actions github-actions bot added the Image (next/image) Related to Next.js Image Optimization. label May 23, 2024
@vitalyiegorov

This comment has been minimized.

@jonsoku-dev
Copy link

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

@karlmacklin
Copy link

karlmacklin commented Nov 25, 2024

@vitalyiegorov Are you also on Docker on Alpine Linux?

We are seeing memory leaks on version 14.2.18 on alpine linux, in Docker, on Auzre, so it seems this is a perfect explanation for our problems.

Edit:

Celebrated too early..
@adgsenpai I cannot see what this issue states in your reproduction scenario.
I see memory go up for a bit initially, but it never starts accumulating, so it looks health.

@adgsenpai
Copy link
Author

Thank you for your feedback. I was able to resolve the issue by updating the operating system and the version of Next.

@karlmacklin
Copy link

Thank you for your feedback. I was able to resolve the issue by updating the operating system and the version of Next.

You should probably close this issue then.

May I ask what operating system you updated to that fixed the issue for you?

@adgsenpai
Copy link
Author

@karlmacklin Ubuntu 20.04

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked
Projects
None yet
Development

No branches or pull requests

4 participants