Skip to content

Race detector checking failed for AddHook API in redis v9 #2557

Closed
@zcong1993

Description

@zcong1993

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

AddHook API not pass race detector with config MinIdleConns > 0 in redis v9, which v8 works.

Expected Behavior

Redis v9 AddHook API should pass race detector

Current Behavior

Redis v9 AddHook API not pass race detector

Possible Solution

Steps to Reproduce

  1. create a test file
// v9.go
package main

import (
	"github.com/redis/go-redis/v9"
)

func main() {
	red := redis.NewClient(&redis.Options{
		Addr:         "localhost:6379",
		MinIdleConns: 1,
	})
	red.AddHook(noopHook{})
}

type noopHook struct{}

func (h noopHook) DialHook(next redis.DialHook) redis.DialHook {
	return next
}

func (h noopHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
	return next
}

func (h noopHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
	return next
}
  1. run with go run -race v9.go, will panic
  2. create v8 test file
package main

import (
	"context"

	"github.com/go-redis/redis/v8"
)

func main() {
	red := redis.NewClient(&redis.Options{
		Addr:         "localhost:6379",
		MinIdleConns: 1,
	})
	red.AddHook(noopHook{})
}

type noopHook struct{}

func (h noopHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) {
	return ctx, nil
}

func (h noopHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error {
	return nil
}

func (h noopHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) {
	return ctx, nil
}

func (h noopHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error {
	return nil
}
  1. run with go run -race v8.go, it works

Context (Environment)

Detailed Description

Possible Implementation

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