You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlexStocks (via GitHub)" <gi...@apache.org> on 2026/07/28 02:15:40 UTC

[I] [Bug] File descriptor leaks in CacheManager.loadCache and accesslog Filter.openLogFile (P0) [dubbo-go]

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: notifications-unsubscribe@dubbo.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] File descriptor leaks in CacheManager.loadCache and accesslog Filter.openLogFile (P0) [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl closed issue #3553: [Bug] File descriptor leaks in CacheManager.loadCache and accesslog Filter.openLogFile (P0)
URL: https://github.com/apache/dubbo-go/issues/3553


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] File descriptor leaks in CacheManager.loadCache and accesslog Filter.openLogFile (P0) [dubbo-go]

Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on issue #3553:
URL: https://github.com/apache/dubbo-go/issues/3553#issuecomment-5099237161

   go vet check: `registry/servicediscovery/store` and `filter/accesslog` pass with zero default-analyzer warnings. fd leaks are not detected by `go vet` — the `bodyclose` linter (proposed enhanced golangci config) is needed. See #3552 for the full verification note.


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


Re: [I] [Bug] File descriptor leaks in CacheManager.loadCache and accesslog Filter.openLogFile (P0) [dubbo-go]

Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on issue #3553:
URL: https://github.com/apache/dubbo-go/issues/3553#issuecomment-5185847806

   close via #3552


-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org