ISSUE DESCRIPTION Removing a registered or subscribed service leaves stale local…
- User
ISSUE DESCRIPTION
Removing a registered or subscribed service leaves stale local metadata
After a successful unregister or unsubscribe operation, the corresponding provider or consumer URL must no longer participate in local metadata, service matching, or revision calculation. Removing one URL must preserve unrelated registrations. If the remote operation fails, local metadata must not be removed as though the operation succeeded.
Interface
Type: Function Name: RemoveService Path: metadata/metadata.go Input: registryId string, url *common.URL Output: (no return value) Description: Removes a provider service URL from the local metadata for the given registry. Use this during unregister flows to keep the in-memory application-level metadata consistent with the actual exported services.
Type: Function Name: RemoveSubscribeURL Path: metadata/metadata.go Input: registryId string, url *common.URL Output: (no return value) Description: Removes a subscribed service URL from the local metadata for the given registry. Use this during unsubscribe flows to ensure stale subscribed URLs are cleaned from the application-level metadata.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Assistant
Now let's add the wrapper functions in metadata/metadata.go:
Assistant
Good, this confirms that removing service from registryMetadataInfo map will affect revision calc since it iterates over metadataMap. Now let's wire up UnRegister and UnSubscribe in service_discovery_registry.go.
Assistant
Looks identical to what I searched. Let me try using edit with line range instead.
Assistant
Good, that worked. Now let's build the project to make sure everything compiles.
Assistant
Build succeeded. Now let's run the relevant tests.
Assistant
All tests pass. Now let's write a quick reproduction/verification script for the new functions to make sure they work correctly, including edge cases (unrelated registrations preserved, failed remote op doesn't remove local metadata).
Assistant
Need to remove the import since it's the same package now.
Assistant
All passing. Now remove the temporary test file, and let's also verify the failed-remote-op-doesn't-remove-metadata scenario with the service_discovery_registry itself.
Assistant
This confirms my implementation handles both success and failure cases correctly since I only call
metadata.RemoveServiceafterUnRegisterService()returns no error. Let's run the whole test suite one more time to be safe, and view the diff.Assistant
The diff looks clean. Let's run full test suite for affected packages once more, plus a broader test run to be safe.
Assistant
All tests pass across affected packages. Let's finalize with the checklist.
Assistant
Now let's go through the checklist:
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. — The issue wasn't a runtime error/stack trace but a missing-feature/bug:
RemoveServiceandRemoveSubscribeURLfunctions didn't exist inmetadata/metadata.go, and unregister/unsubscribe flows never cleaned up local metadata. I confirmed this by inspectingmetadata/metadata.go(onlyAddService/AddSubscribeURLexisted) andregistry/servicediscovery/service_discovery_registry.go'sUnRegister/UnSubscribe(which never called any removal logic), verifying the "stale metadata" problem existed before my change. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. — I added
RemoveServiceandRemoveSubscribeURLtometadata/metadata.go(delegating to the already-existinginfo.MetadataInfo.RemoveService/RemoveSubscribeURL), and wired them into / in , only invoking them after the underlying remote operation succeeds. I wrote and ran temporary verification tests confirming: removing one URL preserves unrelated ones, and calling remove functions on a non-existent registry doesn't panic.
-
Assistant
- I have thought about edge cases and made sure my fix handles them as well. — Considered: (1) registry ID not present in map → guarded with
existcheck, no-op instead of panic; (2) unrelated registrations must be preserved → the underlyingremoveUrlinmetadata_info.goonly removes the specific URL from the slice keyed byServiceKey(), verified via test that a second unrelated URL remains; (3) remote operation failure must not remove local metadata → in bothUnRegisterandUnSubscribe, the removal call only happens after checking the error returned by the remote operation (UnRegisterService()/serviceNameMapping.Remove(url)) isnil, so failed operations leave metadata untouched (validated against existing testTestServiceDiscoveryRegistryUnRegister_PartialFailsemantics, which returns an error on partial failure, correctly skipping metadata removal in that case sinceUnRegisterService()returns non-nil).
- I have thought about edge cases and made sure my fix handles them as well. — Considered: (1) registry ID not present in map → guarded with
Assistant
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Ran
go build ./...(success), andgo testformetadata/...,registry/servicediscovery/...,registry/..., andcommon/...(all pass, fresh with-count=1too). No pre-existing tests were modified.
All items are addressed. Final diff review before submission:
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Ran
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.