#4395·gofr

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 touches c.File.
  • FileSystemProvider and CommonFileSystem have no Close() method.
  • The FTP adapter has no Close() either, so its control connection is never sent QUIT.
  • The GCS adapter does have a Close(), but nothing ever calls it.

Reproduction

go
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 for c.File.
  • pkg/gofr/datasource/file/interface.go: FileSystemProvider has no Close, and CommonFileSystem doesn't implement one.
  • pkg/gofr/datasource/file/ftp/storage_adapter.go: holds conn *ftp.ServerConn but has no Close/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() error to CommonFileSystem, delegating to the provider when it implements io.Closer.
  • Add Close() to the FTP adapter, calling conn.Quit() under the adapter's lock (see #4376).
  • Close c.File in Container.Close() when it implements io.Closer.
  • Close must also stop the background startRetryConnect loop, for example with a done channel or context, and mark the adapter closed. Otherwise a Connect() still in flight when Close runs could publish a client that never gets closed. This ordering is noted as a known limitation in #4376.