miekg / dns

DNS library in Go
https://miek.nl/2014/august/16/go-dns-package
BSD 3-Clause "New" or "Revised" License
7.99k stars 1.13k forks source link

Passing context param to `ListenAndServe` method #1565

Closed Junaid-Ahm closed 2 months ago

Junaid-Ahm commented 5 months ago

Hi there,

There is a public method ShutdownContext here, which allows context param to be passed. But the method ListenAndServe does not accept context param and always uses context.Background in listenTCP(...) or listenUDP(...) when called from the method ListenAndServer(...).

I know I can construct the listeners myself and use the ActivateAndServe. But it seems to be too much effort when someone is not willing to take on the burden of setting up and maintaining the listeners on their end and only want to pass down context.

I think the easiest way is

If there are no objections, I am happy to make the change and submit the PR.

miekg commented 3 months ago

What initial problem are you solving?

ListenAndServe(...) could take an optional context.Context parameter, which negates to need to put something like that in the server struct?