Skip to content

discov map race #5394

@1426919587

Description

@1426919587

Describe the bug
A clear and concise description of what the bug is.
map 锁出问题了
To Reproduce
Steps to reproduce the behavior, if applicable:
WARNING: DATA RACE
Write at 0x00c000362ba0 by goroutine 70:
runtime.mapassign()
D:/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.10.windows-amd64/src/internal/runtime/maps/runtime_swiss.go:191 +0x0
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).addListener()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:187 +0x3d6
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).monitor()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:330 +0x9e
github.com/zeromicro/go-zero/core/discov/internal.(*Registry).Monitor()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:77 +0x2a6
github.com/zeromicro/go-zero/core/discov.NewSubscriber()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/subscriber.go:43 +0x2c4
github.com/zeromicro/go-zero/zrpc/resolver/internal.(*discovBuilder).Build()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/zrpc/resolver/internal/discovbuilder.go:19 +0xf9
google.golang.org/grpc/internal/resolver/delegatingresolver.New()
D:/gopath/pkg/mod/google.golang.org/grpc@v1.77.0/internal/resolver/delegatingresolver/delegatingresolver.go:131 +0x104f
google.golang.org/grpc.(*ccResolverWrapper).start.func1()
D:/gopath/pkg/mod/google.golang.org/grpc@v1.77.0/resolver_wrapper.go:91 +0x67b
google.golang.org/grpc/internal/grpcsync.(*CallbackSerializer).run()
D:/gopath/pkg/mod/google.golang.org/grpc@v1.77.0/internal/grpcsync/callback_serializer.go:90 +0x1ce
google.golang.org/grpc/internal/grpcsync.NewCallbackSerializer.gowrap1()
D:/gopath/pkg/mod/google.golang.org/grpc@v1.77.0/internal/grpcsync/callback_serializer.go:52 +0x4f

Previous read at 0x00c000362ba0 by goroutine 61:
runtime.mapaccess1()
D:/gopath/pkg/mod/golang.org/toolchain@v0.0.1-go1.24.10.windows-amd64/src/internal/runtime/maps/runtime_swiss.go:43 +0x0
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).setupWatch()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:436 +0x35a
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).watchStream()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:396 +0x9c
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).watch()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:379 +0x106
github.com/zeromicro/go-zero/core/discov/internal.(*cluster).monitor.func1()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/discov/internal/registry.go:333 +0x84
github.com/zeromicro/go-zero/core/threading.(*RoutineGroup).Run.func1()
D:/gopath/pkg/mod/github.com/zeromicro/go-zero@v1.9.4/core/threading/routinegroup.go:23 +0x86

  1. The code is

    func (c *cluster) monitor(key watchKey, l UpdateListener) error {
     cli, err := c.getClient()
     if err != nil {
     	return err
     }
    
     c.addListener(key, l)
     rev := c.load(cli, key)
     c.watchGroup.Run(func() {
     	c.watch(cli, key, rev)
     })
    
     return nil

}

go的协程1

Image

go的协程2
watch-》watchStream-》setupWatch

Image

2. The error is
map race

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Environments (please complete the following information):**
- OS: [Windows]
- go-zero version 1.9.4
- goctl version 1.9.4

**More description**
Add any other context about the problem here.

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