Stirling-PDF icon indicating copy to clipboard operation
Stirling-PDF copied to clipboard

[Bug]: Internal Server Error:jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: Java heap space

Open zi-ming opened this issue 1 year ago • 5 comments

Installation Method

Docker

The Problem

When I compressed a larger volume of PDF, prompt: Internal Server Error: jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: Java heap. How can I solve this problem?

Version of Stirling-PDF

0.35.0

Last Working Version of Stirling-PDF

No response

Page Where the Problem Occurred

No response

Docker Configuration

No response

Relevant Log Output

No response

Additional Information

No response

Browsers Affected

No response

No Duplicate of the Issue

  • [X] I have verified that there are no existing issues raised related to my problem.

zi-ming avatar Dec 02 '24 16:12 zi-ming

Hey @zi-ming! I'm here to help you with any bugs, questions, or contributions you have for Stirling-PDF. Let's squash this bug together!

To resolve the "Internal Server Error: jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: Java heap space" issue when compressing a large volume of PDF using Stirling-PDF version 0.35.0 with Docker, you can increase the memory limit allocated to the Docker container. The current configuration sets a memory limit of 4G. You can try increasing this limit to provide more heap space for the Java application.

Modify the docker-compose-latest-fat-security.yml file as follows:

services:
  stirling-pdf:
    container_name: Stirling-PDF-Security-Fat
    image: stirlingtools/stirling-pdf:latest-fat
    deploy:
      resources:
        limits:
          memory: 8G  # Increase the memory limit to 8G or more
    ...

After making this change, restart the Docker container to apply the new memory limit. This should help alleviate the OutOfMemoryError by providing more heap space for the application [1].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Dec 02 '24 16:12 dosubot[bot]

Hey @zi-ming! I'm here to help you with any bugs, questions, or contributions you have for Stirling-PDF. Let's squash this bug together!

To resolve the "Internal Server Error: jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: Java heap space" issue when compressing a large volume of PDF using Stirling-PDF version 0.35.0 with Docker, you can increase the memory limit allocated to the Docker container. The current configuration sets a memory limit of 4G. You can try increasing this limit to provide more heap space for the Java application.

Modify the docker-compose-latest-fat-security.yml file as follows:

services:
  stirling-pdf:
    container_name: Stirling-PDF-Security-Fat
    image: stirlingtools/stirling-pdf:latest-fat
    deploy:
      resources:
        limits:
          memory: 8G  # Increase the memory limit to 8G or more
    ...

After making this change, restart the Docker container to apply the new memory limit. This should help alleviate the OutOfMemoryError by providing more heap space for the application [1].

To continue talking to Dosu, mention @dosu.

Thank you very much for your response. My Ubuntu system has 32GB of memory, and following your suggestion, I allocated 12GB of memory to Docker. I then uploaded a 600MB PDF for compression, but it still showed an "Internal Server Error:jakarta.servlet.ServletException: Handler dispatch failed: java.lang.OutOfMemoryError: Java heap space." Furthermore, after the error occurred, Docker did not release the memory, and I had to restart Docker to free it.

zi-ming avatar Dec 02 '24 16:12 zi-ming

Found error in code which causes large memory usage on PDFs containing several images when compression greater than 5-6 is this the cause? Do you not get extreme usage on compression of 4? Will try resolve soon

Frooodle avatar Dec 02 '24 23:12 Frooodle

Version: 0.37.1 Encountered the same error.

nowanti avatar Jan 17 '25 05:01 nowanti

Can you try on the latest 0.40.2 This has better memory management also I suggest using compression level only up to 5 for best performance

Frooodle avatar Feb 06 '25 16:02 Frooodle

Closing due to no reply, please let us know if you still see this issue

Frooodle avatar Feb 20 '25 16:02 Frooodle