File stores are never closed on app shutdown (the FTP adapter has no Close at all)
Author: NitinKumar004Created Sep 27, 2026Updated Oct 1, 2026
Summary
When a GoFr app shuts down, the file store registered with AddFileStore is never closed:
Container.Close()closes the SQL, Redis and PubSub clients (and WebSocket connections), but never touchesc.File.FileSystemProviderandCommonFileSystemhave noClose()method.- The FTP adapter has no
Close()either, so its control connection is never sentQUIT. - The GCS adapter does have a
Close(), but nothing ever calls it.
Reproduction
fs := ftp.New(&ftp.Config{Host: "127.0.0.1", Port: port, User: "u", Password: "p"})
fs.Connect()
_, ok := fs.(io.Closer) // false
// The FTP storage adapter behind it does not implement io.Closer either.Start an app with an FTP file store and stop it. The FTP server only sees the TCP connection drop at process exit, never a QUIT.
Root cause
pkg/gofr/container/container.go:Close()has no branch forc.File.pkg/gofr/datasource/file/interface.go:FileSystemProviderhas noClose, andCommonFileSystemdoesn't implement one.pkg/gofr/datasource/file/ftp/storage_adapter.go: holdsconn *ftp.ServerConnbut has noClose/Quit.pkg/gofr/datasource/file/gcs/storage_adapter.go:Close()exists but is never reached.
Impact
FTP control connections and GCS clients stay open until the process exits. This matters most where Apps are created and torn down inside one process, such as tests or embedded use, and for FTP servers that limit concurrent sessions per user.
Suggested fix
- Add
Close() errortoCommonFileSystem, delegating to the provider when it implementsio.Closer. - Add
Close()to the FTP adapter, callingconn.Quit()under the adapter's lock (see #4376). - Close
c.FileinContainer.Close()when it implementsio.Closer. Closemust also stop the backgroundstartRetryConnectloop, for example with a done channel or context, and mark the adapter closed. Otherwise aConnect()still in flight whenCloseruns could publish a client that never gets closed. This ordering is noted as a known limitation in #4376.
Source: gofr-dev/gofr