Skip to content

SurrealDB Connect() reports connected when username or password is missing, with no log #4313

Closed

Description

@NitinKumar004

Describe the bug

If only one of Username / Password is set, Connect() stops before signing in but leaves the client looking connected, and nothing is logged.

c.db is assigned before authentication runs (pkg/gofr/datasource/surrealdb/surrealdb.go:151):

c.db, err = newDB(ctx, endpoint)

authenticateCredentials then returns the sentinel without logging (surrealdb.go:192-194):

if c.config.Username == "" || c.config.Password == "" {
    return errInvalidCredentialsConfig
}

and Connect() just returns on that error (surrealdb.go:127-130):

err = c.authenticateCredentials(ctx)
if err != nil {
    return
}

Every other method, including HealthCheck (surrealdb.go:727), only treats the client as disconnected when c.db == nil, so the app starts, health says UP, and queries run against an unauthenticated session. The "Successfully connected" log is skipped, but no error is logged either.

The sign-in failure (:200-203) and Use failure (:122-125) paths log, but they have the same problem of leaving c.db set.

To Reproduce

  1. Configure SurrealDB with Username set and Password empty.
  2. Start the app.
  3. No error in the logs, and /.well-known/health reports surrealdb as UP.

Expected behavior

An incomplete credentials config should be logged as an error, and any failure after newDB in Connect() should leave the client in the not-connected state (c.db = nil, ideally closing the half-open connection) so health checks and queries return errNotConnected.

Additional context

Found by @aryanmehrotra while reviewing #4274.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions