Skip to content

False positive G118: context cancellation function not called #1637

@mholt

Description

@mholt

I believe this is a false positive as well:

	ctx, cancel := context.WithCancel(tl.ctx)
	
	job := &ActiveJob{ctx: ctx, cancel: cancel, ...}

	go func(job *ActiveJob) {
		defer func() {
			if r := recover(); r != nil {
				logger.Error("panic",
					zap.Any("error", r),
					zap.String("stack", string(debug.Stack())))
			}
		}()

		logger.Info("running",
			zap.Object("job", row),
			zap.String("state", string(row.State)))

		defer job.cancel() // <-- cancel is called reliably here

		// ...
	})(job)

The cancel() function is called reliably. I do not think it merits a lint error.

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