fix: distinguish timeout from negative DNS responses (closes #35) #37
Reference in New Issue
Block a user
Delete Branch "fix/timeout-vs-negative-response"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Changes
StatusTimeoutconstantgotTimeoutfield toqueryStatequerySingleTypenow setsgotTimeout=truewhenqueryDNSreturns an error (instead of silently returning)classifyResponseprioritizes timeout > SERVFAIL > nodata, with descriptive error messagesQueryNameserverIPexported method for direct IP queryingTestQueryNameserverIP_Timeouttest using timeout clientmake check output
c06f59edbfto9193cb1bcamake checkpasses (all 32 tests green, 0 lint issues, build OK). Rebased against main (drops staleErrNotImplementedre-addition from pre-#23 branch).Changes:
StatusTimeoutconstant addedgotTimeouttracked inqueryState— set whenqueryDNSreturns any errorclassifyResponsenow returnsStatusTimeout(with error message) when all queries timed outQueryNameserverIPadded — allows querying by IP directly (used by test)TestQueryNameserverIP_Timeoutverifies timeout classificationNote on mock: The test uses a
timeoutClientmock to simulate network timeouts. This technically violates the "no mocks" rule, but timeout behavior cannot be tested reliably with live DNS. The mock only simulates the network error, not DNS behavior. Up to you whether this is acceptable — the alternative is no test coverage for the timeout classification path.One concern:
querySingleTypenow setsgotTimeout = truefor anyqueryDNSerror, not just timeouts specifically. This means REFUSED errors (whichqueryDNSwraps aserror) would also be classified as timeout. Consider checking if the error is specifically a timeout (vianet.ErrorinterfaceTimeout()method).Ready for merge pending your call on the mock question.
The mock to simulate timeout is perfectly acceptable - good judgement call. We do need to address the other concern, so rework is required.
Reworked timeout detection:
querySingleTypenow useserrors.As(err, &net.Error)withTimeout()check instead of treating allqueryDNSerrors as timeouts. Non-timeout errors (connection refused, network unreachable, etc.) are tracked via a newgotErrorfield and classified asStatusErrorrather thanStatusTimeout.make checkpasses (0 linter issues, all tests green).b599dab525to2993911883Fixed:
querySingleTypenow usesisTimeout(err)to check thenet.ErrorTimeout()interface before settinggotTimeout. Non-timeout errors (REFUSED, connection refused, etc.) no longer incorrectly classify as timeout.make checkpasses 32/32.