hashicorp / hashicorp/mdns

Any plans to refactor the "Query" and "Lookup" functions to use context instead of a hard timeout?

Open
#111 1 comment 4 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.4k
Forks
225
Avg merge
15h 34m
Merged PRs (30d)
3

Description

Given that results are streaming to a channel, using a context instead of a hard timeout would be more appropriate. Working with a hard timeout within the concurrency model set up in this library somewhat awkward and limiting. For example what if I want to read entries from a channel until I find all of the entries I am looking for and then move on? Currently to do this you either have to:

1. Choose an overly long timeout and be okay with the goroutine running `Query` not exiting until potentially long after its task has be fulfilled
2. Repeat calls to `Query` with a short timeout in a loop

`1` means sacrificing performance and even if its unlikely to be a bottleneck in your applications resource use its still pretty grating to anyone who cares about good design. Whereas `2` feels like over-engineering due to utilizing a clunky API.

Having these functions take a `context` would allow library users to readily choose whether they want to use the timeout model or logic driven cancellation using well defined and understood patterns from the `go` standard library.

Contributor guide

Open the contributing guide

Research direction

Start by locating the Query and Lookup functions and tracing how their streaming channels and hard timeouts control goroutine lifetime. Review their callers and existing tests to determine the API and cancellation behavior that must be covered; the work is done when callers can use context-driven cancellation without breaking current result streaming.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.