Aias00 commented on PR #3438:
URL: https://github.com/apache/dubbo-go/pull/3438#issuecomment-4727597289
## Addressed Copilot Review Feedback
All three review comments have been addressed in the latest commit (8bb4ab5):
### 1. Three-state atomic instead of two-state bool
**Before:** `uatomic.Bool` with CAS(false→true) before Connect, causing
waiters to see init==true before initialization completes.
**After:** Replaced with `uatomic.Int32` using three states:
- `0` = uninitialized
- `1` = initializing
- `2` = initialized
CAS now transitions `0→1` (not `0→2`), so waiters never observe a "ready"
state until Connect actually succeeds. On failure, state resets to `0` for
retry.
### 2. sync.Cond instead of spin-wait
**Before:** `for !cl.init.Load() { time.Sleep(10ms) }` — polling with fixed
sleep.
**After:** `sync.Cond` with `Broadcast()` when initialization completes
(success or failure). Waiters call `cl.initCond.Wait()` and are woken
immediately when the initializing goroutine finishes, eliminating both latency
and CPU waste.
### 3. Test: buffered channel instead of t.Errorf from goroutines
**Before:** `t.Errorf` called directly from concurrent goroutines.
**After:** Errors are collected into a buffered channel and asserted from
the main test goroutine after `wg.Wait()`.
Additionally, all concurrent waiters now receive the same error result when
initialization fails (previously they silently returned nil).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]