[BUG] Polaris interface registry may keep stale providers after initial load
👋 Thank you for your feedback!
This issue tracks a potential stale provider problem found by code inspection in the Polaris interface-level registry path. It is similar to the initial subscribe snapshot problem fixed for Nacos in #3479, but it affects registry/polaris.
🔧 Environment Information
🚀 Go Version
Not Go-version specific.
📦 Dubbo-go Version
Current main; older versions with the same Polaris interface-level registry implementation may also be affected.
🖥️ Server Configuration
Any provider registered through Polaris interface-level registry.
💻 Client Configuration
Dubbo-go consumer using Polaris interface-level registry.
🌐 Protocol Configuration
Not protocol-specific.
📋 Registry Configuration
Polaris interface-level registry path (registry/polaris). This is not about the application-level service discovery path.
💾 Operating System
Not OS-specific.
🐛 Issue Details
📝 Bug Description
polarisRegistry.LoadSubscribeInstances synchronously loads the initial provider instances and notifies the directory with per-instance ADD events. Later, polarisRegistry.Subscribe starts a Polaris watcher. The watcher sends the initial WatchService full instance list as EventTypeAdd events for each current instance.
If an instance is returned by LoadSubscribeInstances but disappears before WatchService is established, the directory has already cached an invoker for the old instance. The watcher only emits ADD events for the current list and does not generate a DEL for the instance that disappeared between the synchronous load and the watcher startup. As a result, the stale invoker can remain in the directory cache.
Relevant code:
registry/polaris/registry.go:LoadSubscribeInstancescallsGetInstancesand notifies each instance asEventTypeAdd.registry/polaris/core.go:startWatchsendsresp.GetAllInstancesResp.InstancesasEventTypeAdd.registry/polaris/listener.go: the listener forwards each instance as an incrementalNotifyevent.registry/directory/directory.go: incrementalADDis idempotent for existing keys but does not remove old keys; stale entries require an explicitDELor a full-listNotifyAllrefresh.
🔄 Steps to Reproduce
This is a code-path race scenario:
- Configure a Dubbo-go consumer to use the Polaris interface-level registry implementation.
- Provider instance A is present when the consumer starts.
LoadSubscribeInstancesloads A and notifies the directory withADD(A).- Before the Polaris watcher finishes
WatchServiceinitialization, A is removed or replaced by B. - The watcher initial response contains only the current instance list, for example B or empty.
- The watcher emits
ADD(B)or no event for A, but noDEL(A)is emitted. - The directory may keep the stale invoker for A.
Minimal regression test scenario:
- Use a fake Polaris consumer API.
- Make
GetInstancesreturn instance A. - Call
polarisRegistry.LoadSubscribeInstances(url, notify)and assertnotifyreceivesADD(A). - Start the subscribe/watch path with the same service.
- Make the first
WatchServicesnapshot return only B, or an empty list. - Assert the directory/listener receives a removal for A, either as
DEL(A)or through a full-list refresh that removes A. - With the current implementation, A is not removed because the watcher first snapshot is converted only to incremental
ADDevents.
Concrete event sequence:
LoadSubscribeInstances: [A] -> Notify ADD(A)
WatchService snapshot: [B] -> current code emits ADD(B) only
Expected reconciliation: [B] -> ADD(B) plus DEL(A), or NotifyAll([B])
Actual result: directory may keep A and B
✅ Expected Behavior
Instances loaded by LoadSubscribeInstances should be reconciled with the first Polaris watcher snapshot. If an initially loaded instance is absent from the first watcher result, Dubbo-go should remove it from the directory cache, either by emitting a DEL event or by applying full-list refresh semantics.
❌ Actual Behavior
The initial synchronous load and the watcher path are not reconciled. The watcher initial snapshot is treated as incremental ADD events only. Providers that were added by LoadSubscribeInstances but are absent from the first watcher snapshot may remain as stale invokers.
💡 Possible Solution
Apply a similar reconciliation strategy to the Nacos fix in #3479, or change Polaris watcher initial snapshot handling to full-list semantics:
- Keep the
LoadSubscribeInstancesresult as an initial snapshot baseline and seed the Polaris listener/watcher before processing the first watcher response, so missing instances can produceDELevents. - Alternatively, treat the first
WatchServicefull instance list as a complete refresh and notify the directory viaNotifyAll, allowing it to remove cached invokers not present in the current list.
The implementation should be limited to the Polaris interface-level registry path and should not affect the application-level service discovery path, which already uses full-list NotifyAll refresh semantics.
Can I have a try
close via #3482