feat(metadata): add concurrency safety for application-level metadata state (#3353) (#3367) * feat(metadata): add internal RWMutex for MetadataInfo and fix json serialization (#3353) Add sync.RWMutex to MetadataInfo struct with json:"-" / hessian:"-" tags to skip serialization. All mutating methods (AddService, RemoveService, AddSubscribeURL, RemoveSubscribeURL) acquire the write lock, and read methods (GetExportedServiceURLs, GetSubscribedURLs, GetServices) acquire the read lock. The new GetServices method returns a snapshot copy. Signed-off-by: jieguo-coder <1193249232@qq.com> * feat(metadata): add lock protection for global registry and instances (#3353) Add sync.RWMutex to protect registryMetadataInfo in metadata.go and instances in report_instance.go. Extract getMetadataReportUnsafe helper to avoid reentrant RLock deadlock in GetMetadataReportByRegistry fallback. Fix nacos report_test to use pointer to MetadataInfo for json.Marshal. Signed-off-by: jieguo-coder <1193249232@qq.com> * feat(metadata): fix concurrency safety in listener callbacks and external calls (#3353) Add mutex locking to AddListenerAndNotify and RemoveListener to protect shared fields listeners and serviceUrls. Replace direct access to MetadataInfo.Services with safe GetServices method in OnEvent and convertV2 to prevent unprotected map reads. Signed-off-by: jieguo-coder <1193249232@qq.com> * style: format import blocks using dubbo-go imports-formatter Signed-off-by: jieguo-coder <1193249232@qq.com> * style: format metadata.go and report_instance.go to pass CI Signed-off-by: jieguo-coder <1193249232@qq.com> * fix(metadata): resolve data races pointed out in code review Signed-off-by: jieguo-coder <1193249232@qq.com> * test: fix failing tests and improve unit test coverage Signed-off-by: jieguo-coder <1193249232@qq.com> * test: fix testifylint error by avoiding require in goroutines Signed-off-by: jieguo-coder <1193249232@qq.com> * fix(metadata): deep copy ServiceInfo to prevent write-on-read data race and reduce lock granularity in report creation Signed-off-by: jieguo-coder <1193249232@qq.com> * chore: trigger CI re-run for codecov gpg issue * refactor(metadata): implement no-lock helper to fix data race and avoid deadlocks in ReplaceExportedServices Signed-off-by: jieguo-coder <1193249232@qq.com> * test: fix compilation error in instance changed listener tests by adding missing registryId argument Signed-off-by: jieguo-coder <1193249232@qq.com> * fix(metadata): add RLock around global map lookup in RemoveService and RemoveSubscribeURL to prevent concurrent map read/write Signed-off-by: jieguo-coder <1193249232@qq.com> --------- Signed-off-by: jieguo-coder <1193249232@qq.com>
English | 中文
Apache Dubbo-go is a high-performance RPC and microservice framework compatible with other Dubbo language implementations. It leverages Golang's concurrency features to provide efficient service governance, including service discovery, load balancing, and traffic management. Dubbo-go supports multiple protocols, such as Dubbo, JSONRPC, Triple(gRPC-compatible), gRPC, HTTP, HTTP2, and HTTP/3 (experimental), ensuring seamless integration in heterogeneous environments.
You can visit the official website for more information.
For detailed changes, refer to CHANGELOG.md.
3.3.1: Optimized configuration hot-reloading with content-based caching to prevent redundant notifications. Added experimental HTTP/3 support, Apollo integration, and Triple protocol OpenAPI generation. Fixed critical race conditions in service discovery under high-concurrency.
3.3.0: Introduced script routing, multi-destination conditional routing, Triple protocol keepalive and connection pooling, Nacos multi-category subscriptions, and enhancements for observability and interoperability.
To install Dubbo-go, use the following command:
go get dubbo.apache.org/dubbo-go/v3@latest
You can learn how to develop a dubbo-go RPC application step by step in 5 minutes by following our Quick Start demo.
It's as simple as the code shown below, you define a service with Protobuf, provide your own service implementation, register it to a server, and start the server.
func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
resp := &greet.GreetResponse{Greeting: req.Name}
return resp, nil
}
func main() {
srv, _ := server.NewServer(
server.WithServerProtocol(
protocol.WithPort(20000),
protocol.WithTriple(),
),
)
_ := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{})
if err := srv.Serve(); err != nil {
logger.Error(err)
}
}
After the server is up and running, call your service via cURL:
curl \ --header "Content-Type: application/json" \ --data '{"name": "Dubbo"}' \ http://localhost:20000/greet.GreetService/Greet
Or, you can start a standard dubbo-go client to call the service:
func main() {
cli, _ := client.NewClient(
client.WithClientURL("127.0.0.1:20000"),
)
svc, _ := greet.NewGreetService(cli)
resp, _ := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
logger.Infof("Greet response: %s", resp.Greeting)
}
See the samples for detailed information on usage. Next, learn how to deploy, monitor and manage the traffic of your dubbo-go application by visiting the official website.
Dubbo-go provides robust service governance capabilities:
The tools/ directory and the dubbogo/tools repository provide several utilities to streamline your Dubbo-Go development experience.
A tool that provides JSON Schema for Dubbo-Go configuration files, enabling editor assistance such as completion, hints, and validation.
For usage details, see the dubbo-go-schema README.
A command-line tool for bootstrapping, managing, and debugging Dubbo-Go applications.
A protoc plugin that generates Go client and server code for the Triple protocol from .proto definition files.
Note: This tool replaces the deprecated protoc-gen-dubbo3grpc and deprecated protoc-gen-go-triple.
For usage details, see the protoc-gen-go-triple README.
A formatting tool for Dubbo-Go developers that organizes Go import blocks according to the community style guide.
For usage details, see the imports-formatter README.
A warning-only scanner that detects exported variadic RPC contracts and prints migration guidance for cross-language scenarios.
Run make rpc-contract-check to use it locally.
Contributions, issues, and discussions are welcome. Please visit CONTRIBUTING for details on submitting patches and the contribution workflow.
Join our discussion group through Ding talk or WeChat.
If you are using apache/dubbo-go and think that it helps you or want to contribute code for Dubbo-go, please add your company to the user list to let us know your needs.
Apache Dubbo-go software is licensed under the Apache License Version 2.0. See the LICENSE file for details.