#4370·gofr

GCS file store panics with nil pointer on file operations while not connected

Author: NitinKumar004Created Sep 24, 2026Updated Sep 24, 2026

Describe the bug

If the GCS bucket isn't reachable when the app starts, Connect() logs an error and starts a background retry (pkg/gofr/datasource/file/gcs/fs.go:68-78), and the app keeps running with storageAdapter.bucket == nil. Most adapter methods use s.bucket without checking it:

pkg/gofr/datasource/file/gcs/storage_adapter.go:255

go
attrs, err := s.bucket.Object(name).Attrs(ctx)

Same in NewReader (:164), NewRangeReader (:182), StatObject (:255), DeleteObject (:279), CopyObject (:306-307), ListObjects (:321) and ListDir (:345). (*storage.BucketHandle)(nil).Object(...) dereferences the handle, so a handler that calls e.g. ctx.File.Stat(...), Open, ReadDir or Remove before the retry succeeds panics instead of getting an error.

Only Health, NewWriter, NewWriterWithOptions and SignedURL check for nil (:137, :197, :213, :505). The Azure and FTP adapters already guard their clients (shareClient == nil / conn == nil).

To Reproduce

go
fs := gcs.New(&gcs.Config{EndPoint: "http://127.0.0.1:1", BucketName: "bkt"})
_, err := fs.Stat("a.txt")
// panic: runtime error: invalid memory address or nil pointer dereference

In an app: register a GCS store whose bucket is unreachable at startup, then hit any handler that reads a file. The request panics (recovered as a 500) until the background retry connects.

Expected behavior

Adapter methods should return an error (e.g. the existing errGCSClientNotInitialized) when s.bucket is nil, like Health/NewWriter do and like the Azure and FTP adapters.

Additional context

Noticed while writing the race repro for the GCS adapter follow-up to #4357. Whatever makes the adapter fields race-free should also cover the nil check.