Aias00 opened a new pull request, #3441:
URL: https://github.com/apache/dubbo-go/pull/3441
## Problem
`addListener()` in `config_center/nacos/listener.go` created
`context.WithCancel(context.Background())` but the returned `cancel` function
was **never called**, causing a goroutine and context leak. Additionally,
`removeListener()` never called `CancelListenConfig` to unsubscribe from the
nacos server, leaving stale config change listeners active indefinitely even
after all listeners were removed.
## Changes
### `config_center/nacos/listener.go`
- **Remove unused `context.WithCancel` calls** in `addListener()` — the
cancel functions were stored but never invoked, leaking contexts and goroutines
- **Replace `context.CancelFunc` value type with `struct{}`** in the inner
`sync.Map` since the cancel function served no purpose
- **Remove unused `"context"` import**
- **In `removeListener()`, call `CancelListenConfig`** when the last
listener for a key is removed, matching the behavior of Apollo
(`RemoveChangeListener`) and File (`watch.Remove`) implementations
- **Clean up `keyListeners` entry** when no listeners remain for a key
- **Add nil client guard** for test compatibility
### `config_center/nacos/impl.go`
- Update `keyListeners` type comment from `context.CancelFunc` to `struct{}`
## Before vs After
| Scenario | Before | After |
|----------|--------|-------|
| `addListener` creates context | `context.WithCancel` called but cancel
never used | No context creation, `struct{}{}` stored |
| `removeListener` removes last listener | Only deletes map entry, nacos
subscription leaks | Deletes map entry **and** calls `CancelListenConfig` |
| Listener goroutine cleanup | Never cleaned up | Cleaned up when all
listeners removed |
## Testing
- All existing tests pass (`go test ./config_center/nacos/...`)
- Project compiles cleanly (`go build ./...`)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
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]