AlexStocks opened a new issue, #3553:
URL: https://github.com/apache/dubbo-go/issues/3553
## Description
Several code paths open files (`os.Open` / `os.OpenFile`) but do not close
the file descriptor on every return path, causing file descriptor leaks in
long-running processes.
## Affected locations
### 1. `registry/servicediscovery/store/cache_manager.go` — `loadCache`
(L106-L127)
```go
cf, err := os.Open(cm.cacheFile) // L107
if err != nil {
return err
}
decoder := gob.NewDecoder(cf)
for {
err = decoder.Decode(&it)
if err != nil {
if err.Error() == "EOF" { break }
return err // L120: cf is NOT closed here
}
cm.cache.Add(it.Key, it.Value)
}
return cf.Close() // L126: only the success path
closes
```
- On decode error the file handle is leaked.
- There is no `defer cf.Close()` right after a successful open.
- Risk: repeated cache loads / reloads accumulate open fds and can exhaust
the fd limit under load.
### 2. `filter/accesslog/filter.go` — `openLogFile` (L321-L349)
```go
logFile, err := os.OpenFile(accessLog, ...) // L322
fileInfo, err := logFile.Stat()
if err != nil { return nil, err } // L331: logFile leaked
if now != last {
err = os.Rename(accessLog, accessLog+"."+now)
if err != nil { return nil, err } // L345: logFile leaked
logFile, err = os.OpenFile(accessLog, ...) // L347: old handle lost
}
return logFile, err
```
- On `Stat()` failure, on `Rename()` failure, and during daily log rotation
the previously opened `*os.File` is leaked.
- Risk: long-running services with access logging leak fds over time.
## Suggested fix
- `loadCache`: add `defer cf.Close()` immediately after the open succeeds
(and drop the manual `cf.Close()`).
- `openLogFile`: ensure every early-return path closes the previously opened
handle, or restructure with a `defer` + named return so the handle is always
released.
## Severity
P0 — deterministic resource leak on error / rotation paths in long-running
services.
## Environment
- Reproducible on current `develop` tip (3.3.2 prep).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]