Skip to content

False Positive on a Lambda function that takes a Mongo SessionContext #24

@blainenelson

Description

@blainenelson

In the following function

func (d *storage) WithTransaction(
	ctx context.Context,
	fn func(context.Context) error,
) error {
	sess, err := d.client.StartSession()
	if err != nil {
		return err
	}
	defer sess.EndSession(ctx)

	_, err = sess.WithTransaction(
		ctx,
		func(sessCtx mongo.SessionContext) (interface{}, error) {
			return nil, fn(sessCtx)
		},
	)
	return err
}

we are now seeing a False Positive

Function `WithTransaction$1` should pass the context parameter (contextcheck)
		func(sessCtx mongo.SessionContext) (interface{}, error) {

It appears there is an issue in creating a lambda function in this way, perhaps because the lambda function takes a mongo.SessionContext instead of a context.Context even though the former extends the latter: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#SessionContext

This issue appears to have arisen with the latest release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions