Implement full context support in ZDNS and better SIGTERM/SIGINT handling #538
+187
−110
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On Mac, there's always been an annoying behavior (existing back to at least
v1.1.0
that I saw) where SIGINT (ctrl + C
) wouldn't kill ZDNS. I've had ZDNS continue after SIGINT for multiple minutes, and I end up just closing the terminal and opening another. Linux doesn't seem to have this behavior and ZDNS will exit immediately.This PR implements both:
context.Context
's in ZDNS. Now the main API's (ExternalLookup()
, etc.) all accept actx
object.SIGINT
andSIGTERM
and cancel the maincontext.Context
. This ensures ZDNS exits quickly on Mac.Limitation
2 Second Delay in Cancellation
With this PR, ZDNS on Mac continues for 2-3 seconds post SIGINT. Using stack dumps, I noticed all goroutines are stuck in a
zmap/dns
lookup. At first this was really surprising since all thedns
lookups we do use a context object which should be canceled when the main context is. However, looking closer at the source code forzmap/dns
, only thectx.Deadline
is used to configure timeouts on the DNS connection object, and our default--network-timeout
is2s
. So we can't cancel in-progress DNS requests and will have to let them expire. Regardless, this seems strictly better than our current state.Final Status Update
Currently, the status handler will print a finalScan Complete; X names scanned...
with SIGINT. Wasn't sure if it'd be better to just immediately quit or print this.Update - Per PR discussion, we now print a
Scan Aborted
instead ofScan Complete
to indicate to the user we aborted due to their signal and didn't exit cleanly.Testing
v1.1.0 Behavior
Screen.Recording.2025-04-10.at.4.34.02.PM.mov
This PR Behavior
Screen.Recording.2025-04-15.at.2.27.19.PM.mov