ring-clojure / ring-clojure/ring
ring.util.response/resource-response triggers JDK bug and leaks file descriptors
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 3.9k
- Forks
- 528
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj#L288 calls .getLastModified which leaks a file descriptor per https://bugs.openjdk.java.net/browse/JDK-8224095
This led to my service failing due to running into the file descriptor ulimit, netty failing to accept new connections, etc. Problem was clear through through /proc/xxx/fd growth and then confirmed with a YourKit memory dump which showed 16K+ Not Closed Files with creation backtraces through connection-last-modified.
Depending on usage pattern and garbage collection this issue may be hidden by the finalizer. However when under load without GC pressure, the file descriptors can be exhausted before this happens.
Workaround: replace use of resource-response with something that bypasses the getLastModified call. I'm considering memoizing all my resource responses (using byte[] bodies) as I have a very small footprint of resources I want to serve.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at ring-core/src/ring/util/response.clj:288 and review the .getLastModified call alongside the linked JDK-8224095 report. Reproduce repeated resource-response calls while watching /proc file-descriptor growth; done means serving resources no longer leaks descriptors under load without relying on garbage collection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure, java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100