Skip to content

Fix: Subscriber handler errors silently swallowed causing potential data loss #3215

@NitinKumar004

Description

@NitinKumar004

Bug Description

In pkg/gofr/subscriber.go:69-72, when a subscription handler returns an error, it is logged but then discarded by returning nil. This breaks error propagation and can lead to silent data loss.

Root Cause

The error from the handler is intentionally replaced with nil:

err = func(ctx *Context) error {
    defer func() {
        panicRecovery(recover(), ctx.Logger)
    }()
    return handler(ctx)
}(msgCtx)

if err != nil {
    s.container.Logger.Errorf("error in handler for topic %s: %v", topic, err)
    return nil  // BUG: error is swallowed, caller sees success
}

Additionally, on line 77, msg.Commit() is called without checking its return value:

if msg.Committer != nil {
    msg.Commit()  // error return value ignored
}

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