[Go] Fix data race in receiveMessage for push and simple consumers (#1275)

The err and resps variables were shared between the main goroutine
and a spawned goroutine without synchronization, causing a data race
detectable by Go's race detector. The goroutine wrote to both
variables while the select handler read them concurrently.

Move resps and err into the goroutine as local variables, and pass
results back through a typed channel (receiveResult struct) instead.
This also fixes push_consumer.go not signaling the done channel on
non-EOF errors, which previously caused it to wait for context
timeout instead of returning the actual error immediately.

Affected:
- golang/push_consumer.go: receiveMessage()
- golang/simple_consumer.go: receiveMessage()

Co-authored-by: guyinyou <guyinyou.gyy@alibaba-inc.com>
2 files changed
tree: fca2cfa760638cc4e6b81cf1d7ddaa2cd42662cd
  1. .github/
  2. cpp/
  3. csharp/
  4. docs/
  5. golang/
  6. java/
  7. nodejs/
  8. php/
  9. python/
  10. rust/
  11. style/
  12. .asf.yaml
  13. .codecov.yml
  14. .gitignore
  15. .gitmodules
  16. .licenserc.yaml
  17. LICENSE
  18. NOTICE
  19. README-CN.md
  20. README.md
README.md

RocketMQ Clients - Collection of Client Bindings for Apache RocketMQ

License Build

English | 简体中文 | RocketMQ Website

Overview

Client bindings for Apache RocketMQ, as known as RocketMQ 5.x SDK. All of them follow the specification of rocketmq-apis, replacing 4.x remoting-based counterparts. Clients in this repository are built on top of Protocol Buffers and gRPC.

Goal

Provide cloud-native and robust solutions for Java, C++, C#, Golang, Rust and all other mainstream programming languages.

Features and Status

  • Ready - ✅
  • Work in progress - 🚧
FeatureJavaC/C++C#GolangRustPythonNode.jsPHP
Producer with standard messages🚧
Producer with FIFO messages🚧
Producer with timed/delay messages🚧
Producer with transactional messages🚧
Producer with recalling timed/delay messages🚧
Simple consumer🚧
Push consumer with concurrent message listener🚧
Push consumer with FIFO message listener🚧
Push consumer with FIFO consume accelerator🚧
Priority Message🚧

Prerequisite and Build

This project is organized as a monorepo, with each language's bindings containing specific instructions in their respective subdirectories for building the project. As the rocketmq-apis submodule is incorporated into the project and could be utilized by some bindings, we highly advise cloning the repository by executing the command below:

git clone --recursive git@github.com:apache/rocketmq-clients.git

Contributing

Similar to other projects of Apache RocketMQ, any attempt to make this project better is welcome, including but not limited to filing a bug report, correcting type error or document writing to complete feature implementation. Do not hesitate to make a pull request if this project catches your attention.

Related

License

Apache License, Version 2.0 Copyright (C) Apache Software Foundation