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.
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.
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.
Each request therefore generated a new temporary directory on the server.
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.
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.
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.
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.
After upgrading the gateway to version 5.2.16, the 500 errors disappeared and the service remained stable.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
