# java.net.SocketException: Too many open files

- **ID:** `java/socketexception-too-many-open-files`
- **Domain:** java
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The JVM process has exhausted the file descriptor limit set by the operating system, typically due to unclosed sockets, file streams, or other I/O resources in the application.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |
| Linux kernel 5.x | active | — | — |

## Workarounds

1. **Use try-with-resources to ensure all Closeable resources (sockets, streams) are automatically closed. Review code for missing close() calls in finally blocks or using try-with-resources.** (90% success)
   ```
   Use try-with-resources to ensure all Closeable resources (sockets, streams) are automatically closed. Review code for missing close() calls in finally blocks or using try-with-resources.
   ```
2. **Monitor the open file count using lsof on Linux to identify which resources are leaking. Use that information to fix the specific leak.** (85% success)
   ```
   Monitor the open file count using lsof on Linux to identify which resources are leaking. Use that information to fix the specific leak.
   ```
3. **Temporarily increase the file descriptor limit for the JVM process using ulimit or systemd configuration, combined with a fix for the leak.** (75% success)
   ```
   Temporarily increase the file descriptor limit for the JVM process using ulimit or systemd configuration, combined with a fix for the leak.
   ```

## Dead Ends

- **** — Increasing the file descriptor limit on the OS without fixing the leak only delays the crash; the leak continues. (70% fail)
- **** — Restarting the application temporarily frees descriptors but does not fix the root cause of resource leaks. (85% fail)
- **** — Adding more memory does not affect file descriptor limits; the issue is about OS limits, not heap. (95% fail)
