Skip to content

Add service removed events to Browse#281

Open
backkem wants to merge 2 commits into
mainfrom
browse-service-removed
Open

Add service removed events to Browse#281
backkem wants to merge 2 commits into
mainfrom
browse-service-removed

Conversation

@backkem

@backkem backkem commented Jun 10, 2026

Copy link
Copy Markdown
Member

Browse so far only ever said hello: an instance was reported once, its records silently fell out of cache monitoring, and a service that left the network stayed in the consumer's view forever. Any real browse UI or discovery loop needs the goodbye too.

  • ServiceEvent.Type distinguishes ServiceAdded from ServiceRemoved, fired on goodbye (RFC 6762 §10.1) or unrefreshed expiry of the instance PTR. Returning instances are re-reported as fresh adds.
  • Emitted instances now stay in cache refresh (§5.2); previously they expired silently right after the first report.
  • Backward compat is constructor-scoped, same pattern as Functional options pattern with NewServer() API #255's WithRecordTypes/WithCacheRefresh defaults: new WithServiceEventTypes option, and legacy Server() defaults to ServiceAdded only, so pre-existing code never sees the new event type. compat_test.go pins the whole legacy contract.
  • OnServiceEvent replaces OnServiceDiscovered (deprecated alias kept): the stream carries lifecycle events now, not just discoveries.

Design: one removal pathway. Goodbyes are retained 1s in the cache and both goodbye and natural expiry surface through sweep(), which now returns what it removed. Removal is driven by the instance PTR only; cache-flush rdata replacement (§10.2) and cap evictions don't emit events. Also fixes a phantom pending instance created by goodbye PTRs for unknown instances.

Part of #253 (Phase 5).

Emitted instances dropped out of cache monitoring: their records
expired silently and a departed service stayed in the consumer's
view forever. Browse now keeps emitted instances monitored (refresh
per RFC 6762 §5.2) and emits ServiceRemoved when the instance PTR
is goodbye'd (§10.1) or expires unrefreshed. Returning instances
are reported as fresh adds.

API: ServiceEvent.Type, OnServiceEvent (OnServiceDiscovered now a
deprecated alias), WithServiceEventTypes option. The legacy Server
constructor delivers only ServiceAdded so code written before
removal events existed never sees the new event type.
@codecov

codecov Bot commented Jun 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.04762% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.09%. Comparing base (84f698c) to head (6b2a2b1).

Files with missing lines Patch % Lines
client.go 91.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #281      +/-   ##
==========================================
+ Coverage   84.11%   85.09%   +0.97%     
==========================================
  Files           8        8              
  Lines        1970     2019      +49     
==========================================
+ Hits         1657     1718      +61     
+ Misses        202      195       -7     
+ Partials      111      106       -5     
Flag Coverage Δ
go 85.09% <94.04%> (+0.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

collectEvents and feedInstance lived in client_test.go (!js) but
were referenced from refresh_test.go, which has no js constraint
and is compiled for the WASM test target.
@backkem backkem requested review from JoTurk and jwetzell June 10, 2026 19:16
@backkem

backkem commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@jwetzell we can also consider adding an OnServiceUpdate event when we add the Update(svc) method alongside Register/Unregister.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant