Why Did My Spring Cloud Gateway Crash? Uncovering Inode Exhaustion and the Fix

After a sudden 500 error crippled an online service, the author traced the issue to Spring Cloud Gateway’s HttpMessageReader creating temporary directories for every request, eventually exhausting inode space; the article explains the root cause, inode basics, and how upgrading to version 5.2.16 resolves the problem.

Su San Talks Tech
Su San Talks Tech
Su San Talks Tech
Why Did My Spring Cloud Gateway Crash? Uncovering Inode Exhaustion and the Fix

Timely Handling

The gateway (Spring Cloud Gateway) returned 500 errors, so the author simply restarted the service, which appeared to resolve the issue temporarily.

Problem Investigation

Although no new deployment had been made, a massive influx of requests (estimated 3 million over two days) caused the gateway to fail. Logs showed an error when creating a temporary directory, despite ample disk space.

Gateway error log
Gateway error log

The failure originated from the Spring class SynchronossPartHttpMessageReader, which creates a temporary directory for each request to store multipart data, even when the request is not multipart.

Source code analysis
Source code analysis

Each request therefore generated a new temporary directory on the server.

Temporary directory creation
Temporary directory creation

Because the number of requests was huge, the OS ran out of inode entries, causing every subsequent request to fail with a 500 error.

inode

In Unix‑like file systems, an inode stores a file’s metadata (size, timestamps, permissions, etc.). The number of inodes is limited; when they are exhausted, new files or directories cannot be created even if there is free disk space.

tmp

The /tmp directory is meant for temporary files and is usually cleaned by a daemon such as tmpwatch. Restarting the system also clears its contents.

tmpwatch illustration
tmpwatch illustration

Solution

Use tmpwatch to clean old temporary files more aggressively.

Avoid using HttpMessageReader for non‑multipart requests.

Schedule periodic restarts.

Modify the source code to create temporary directories only when parsing multipart data.

Wait for an upstream fix in a newer version.

The author tried the first three options but found them unsatisfactory. Instead, they searched the Spring Cloud Gateway GitHub repository and found related issues where maintainers discussed the behavior.

GitHub issue list
GitHub issue list

Maintainers explained that the temporary directory is created to avoid security risks of a fixed location, and that the implementation was not intended as a bug. However, they later acknowledged that massive directory creation could exhaust inodes and adjusted the code so that directories are only created for multipart parsing.

Maintainer response
Maintainer response

The fix was released in Spring Cloud Gateway version 5.2.16. The new implementation creates a single random temporary directory and reuses it, preventing inode exhaustion.

Release notes for 5.2.16
Release notes for 5.2.16
Code change illustration
Code change illustration

After upgrading the gateway to version 5.2.16, the 500 errors disappeared and the service remained stable.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Spring BootSpring Cloud GatewayHttpMessageReaderinode exhaustiontemporary directory
Su San Talks Tech
Written by

Su San Talks Tech

Su San, former staff at several leading tech companies, is a top creator on Juejin and a premium creator on CSDN, and runs the free coding practice site www.susan.net.cn.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.