dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

[BUG] Polaris interface registry may keep stale providers after initial load

Open AsperforMias opened this issue 4 months ago • 2 comments

👋 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: LoadSubscribeInstances calls GetInstances and notifies each instance as EventTypeAdd.
  • registry/polaris/core.go: startWatch sends resp.GetAllInstancesResp.Instances as EventTypeAdd.
  • registry/polaris/listener.go: the listener forwards each instance as an incremental Notify event.
  • registry/directory/directory.go: incremental ADD is idempotent for existing keys but does not remove old keys; stale entries require an explicit DEL or a full-list NotifyAll refresh.

🔄 Steps to Reproduce

This is a code-path race scenario:

  1. Configure a Dubbo-go consumer to use the Polaris interface-level registry implementation.
  2. Provider instance A is present when the consumer starts.
  3. LoadSubscribeInstances loads A and notifies the directory with ADD(A).
  4. Before the Polaris watcher finishes WatchService initialization, A is removed or replaced by B.
  5. The watcher initial response contains only the current instance list, for example B or empty.
  6. The watcher emits ADD(B) or no event for A, but no DEL(A) is emitted.
  7. The directory may keep the stale invoker for A.

Minimal regression test scenario:

  1. Use a fake Polaris consumer API.
  2. Make GetInstances return instance A.
  3. Call polarisRegistry.LoadSubscribeInstances(url, notify) and assert notify receives ADD(A).
  4. Start the subscribe/watch path with the same service.
  5. Make the first WatchService snapshot return only B, or an empty list.
  6. Assert the directory/listener receives a removal for A, either as DEL(A) or through a full-list refresh that removes A.
  7. With the current implementation, A is not removed because the watcher first snapshot is converted only to incremental ADD events.

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:

  1. Keep the LoadSubscribeInstances result as an initial snapshot baseline and seed the Polaris listener/watcher before processing the first watcher response, so missing instances can produce DEL events.
  2. Alternatively, treat the first WatchService full instance list as a complete refresh and notify the directory via NotifyAll, 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.

AsperforMias avatar Jul 08 '26 14:07 AsperforMias

Can I have a try

Vanillaxi avatar Jul 08 '26 14:07 Vanillaxi

close via #3482

Alanxtl avatar Jul 27 '26 01:07 Alanxtl