|
|
a1d60e |
From daf723176da7bfee5baae928ff1af310a2400289 Mon Sep 17 00:00:00 2001
|
|
|
a1d60e |
From: Bob Halley <halley@dnspython.org>
|
|
|
a1d60e |
Date: Sun, 21 Feb 2016 15:22:21 -0800
|
|
|
a1d60e |
Subject: [PATCH] Set response_time to zero when exceptions occur early.
|
|
|
a1d60e |
|
|
|
a1d60e |
---
|
|
|
a1d60e |
dns/query.py | 12 ++++++++++--
|
|
|
a1d60e |
1 file changed, 10 insertions(+), 2 deletions(-)
|
|
|
a1d60e |
|
|
|
a1d60e |
diff --git a/dns/query.py b/dns/query.py
|
|
|
a1d60e |
index ad6dffd..4e8089f 100644
|
|
|
a1d60e |
--- a/dns/query.py
|
|
|
a1d60e |
+++ b/dns/query.py
|
|
|
a1d60e |
@@ -204,6 +204,7 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
|
|
|
a1d60e |
(af, destination, source) = _destination_and_source(af, where, port, source,
|
|
|
a1d60e |
source_port)
|
|
|
a1d60e |
s = socket.socket(af, socket.SOCK_DGRAM, 0)
|
|
|
a1d60e |
+ begin_time = None
|
|
|
a1d60e |
try:
|
|
|
a1d60e |
expiration = _compute_expiration(timeout)
|
|
|
a1d60e |
s.setblocking(0)
|
|
|
a1d60e |
@@ -224,7 +225,10 @@ def udp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
|
|
|
a1d60e |
'%s instead of %s' % (from_address,
|
|
|
a1d60e |
destination))
|
|
|
a1d60e |
finally:
|
|
|
a1d60e |
- response_time = time.time() - begin_time
|
|
|
a1d60e |
+ if begin_time is None:
|
|
|
a1d60e |
+ response_time = 0
|
|
|
a1d60e |
+ else:
|
|
|
a1d60e |
+ response_time = time.time() - begin_time
|
|
|
a1d60e |
s.close()
|
|
|
a1d60e |
r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac,
|
|
|
a1d60e |
one_rr_per_rrset=one_rr_per_rrset)
|
|
|
a1d60e |
@@ -301,6 +305,7 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
|
|
|
a1d60e |
(af, destination, source) = _destination_and_source(af, where, port, source,
|
|
|
a1d60e |
source_port)
|
|
|
a1d60e |
s = socket.socket(af, socket.SOCK_STREAM, 0)
|
|
|
a1d60e |
+ begin_time = None
|
|
|
a1d60e |
try:
|
|
|
a1d60e |
expiration = _compute_expiration(timeout)
|
|
|
a1d60e |
s.setblocking(0)
|
|
|
a1d60e |
@@ -320,7 +325,10 @@ def tcp(q, where, timeout=None, port=53, af=None, source=None, source_port=0,
|
|
|
a1d60e |
(l,) = struct.unpack("!H", ldata)
|
|
|
a1d60e |
wire = _net_read(s, l, expiration)
|
|
|
a1d60e |
finally:
|
|
|
a1d60e |
- response_time = time.time() - begin_time
|
|
|
a1d60e |
+ if begin_time is None:
|
|
|
a1d60e |
+ response_time = 0
|
|
|
a1d60e |
+ else:
|
|
|
a1d60e |
+ response_time = time.time() - begin_time
|
|
|
a1d60e |
s.close()
|
|
|
a1d60e |
r = dns.message.from_wire(wire, keyring=q.keyring, request_mac=q.mac,
|
|
|
a1d60e |
one_rr_per_rrset=one_rr_per_rrset)
|