# file already closed

- **ID:** `go/os-file-already-closed`
- **Domain:** go
- **Category:** io_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Attempting to read, write, or close a file that has already been closed, often due to double-close or using a file after defer Close().

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.13 | active | — | — |
| 1.14 | active | — | — |
| 1.15 | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   Use a sync.Once to ensure Close() is called only once.
   ```
2. **** (90% success)
   ```
   Set the file variable to nil after Close() and check for nil before using.
   ```

## Dead Ends

- **** — The file pointer is not nil after closing; it's the underlying descriptor that is invalid. (70% fail)
- **** — Sync() does not prevent the file from being closed. (60% fail)
