-
Notifications
You must be signed in to change notification settings - Fork 201
Open
Description
I'm working on a clean shutdown procedure for the client / resolver, and I'm unsure how to proceed because I'm a bit confused by the API.
To start a mDNS client, you first create a new resolver, and then call Lookup or Browse:
r, _ := NewResolver()
entries := make(chan *ServiceEntry)
err := r.Browse(ctx, "service", "domain", entries)This raises 2 problems:
- Both
BrowseandLookupreturn immediately. The go routines started by these methods (including the Go routine that reads from the connection) is stopped eventually after the context is done, but there's no way to deterministically tell when this happened. - Although the API seems to suggest otherwise, it's only possible to call
Lookup/Browseonce perResolverinstance, as both of them start reading from theUDPConn(and it only makes sense to read from a connection with a single Go routine).
I can see 2 fundamentally different ways to resolve this:
- Change the API in a way that doesn't suggest that
BrowseandLookupcan be called multiple times.- This would probably mean to remove the
Resolver, and exposeBrowseandLookupas top-level functions. - Make
BrowseandLookupblock until all Go routines have stopped.
- This would probably mean to remove the
- Make it possible to call
BrowseandLookupconcurrently. This would require us to have some demultiplexing logic, to associate received message with a particular lookup. This is easy for responses to a query (they come with an ID), but I'm not sure how one would implement this for the unrequested announcements that servers send out regularly.
Any thoughts, @grandcat and @Stebalien?
Metadata
Metadata
Assignees
Labels
No labels