no dns.exception value for dns.query

59 views
Skip to first unread message

Jeremy C. Reed

unread,
Oct 19, 2023, 11:43:03 AM10/19/23
to dnspyth...@googlegroups.com

try:
response = dns.query.tcp(query, server, timeout=10)
except dns.exception.Timeout:
...
except dns.query.UnexpectedSource as e:
...
except Exception as e:

When I get an exception from dns query, I usually get a message string
with or without an errno (in the string), such as

[Errno 104] Connection reset by peer
[Errno 111] Connection refuse
A DNS query response does not respond to the question asked.
The DNS packet passed to from_wire() has extra junk at the end of it.
(and others)

But periodically, the exception (e) is empty with no value. In all my
recent examples, it is using TCP.

A current example, shown with dig:

$ dig +noedns @216.69.245.249 +tcp
;; communications error to 216.69.245.249#53: end of file

;; communications error to 216.69.245.249#53: end of file

(but with my dnspython query which had no exception value, I did use
edns, had a name, different rrtype, etc.)

Can we raise a generic string instead of nothing?

From a quick look at bind9 code, the ISC_R_EOF happens for DOIO_EOF for
the socket "remote end was closed."

By the way, for this specific example, is there anything else that
could be / should be raised?

If curious ... here is tcpdump output for dig +noedns @216.69.245.249
foo SOA +tcp

10:29:07.986112 IP (tos 0x0, ttl 64, id 21881, offset 0, flags [DF],
proto TCP (6), length 60)
192.168.1.15.33045 > 216.69.245.249.53: Flags [S], cksum 0x9025
(incorrect -> 0x6556), seq 202804432, win 64240, options [mss
1460,sackOK,TS val 2170141751 ecr 0,nop,wscale 7], length 0
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 003c 5579 4000 4006 554c c0a8 010f d845 .<Uy@.@.UL.....E
0x0020: f5f9 8115 0035 0c16 8cd0 0000 0000 a002 .....5..........
0x0030: faf0 9025 0000 0204 05b4 0402 080a 8159 ...%...........Y
0x0040: bc37 0000 0000 0103 0307 .7........
10:29:08.010527 IP (tos 0x0, ttl 52, id 0, offset 0, flags [DF], proto
TCP (6), length 60)
216.69.245.249.53 > 192.168.1.15.33045: Flags [S.], cksum 0x9773
(correct), seq 4195318725, ack 202804433, win 28960, options [mss
1460,sackOK,TS val 1606910469 ecr 2170141751,nop,wscale 7], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 003c 0000 4000 3406 b6c5 d845 f5f9 c0a8 .<..@.4....E....
0x0020: 010f 0035 8115 fa0f 7bc5 0c16 8cd1 a012 ...5....{.......
0x0030: 7120 9773 0000 0204 05b4 0402 080a 5fc7 q..s.........._.
0x0040: 8205 8159 bc37 0103 0307 ...Y.7....
10:29:08.010566 IP (tos 0x0, ttl 64, id 21882, offset 0, flags [DF],
proto TCP (6), length 52)
192.168.1.15.33045 > 216.69.245.249.53: Flags [.], cksum 0x901d
(incorrect -> 0x3552), seq 1, ack 1, win 502, options [nop,nop,TS val
2170141775 ecr 1606910469], length 0
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 0034 557a 4000 4006 5553 c0a8 010f d845 .4Uz@.@.US.....E
0x0020: f5f9 8115 0035 0c16 8cd1 fa0f 7bc6 8010 .....5......{...
0x0030: 01f6 901d 0000 0101 080a 8159 bc4f 5fc7 ...........Y.O_.
0x0040: 8205 ..
10:29:08.010649 IP (tos 0x0, ttl 64, id 21883, offset 0, flags [DF],
proto TCP (6), length 75)
192.168.1.15.33045 > 216.69.245.249.53: Flags [P.], cksum 0x9034
(incorrect -> 0xe167), seq 1:24, ack 1, win 502, options [nop,nop,TS val
2170141775 ecr 1606910469], length 23 55487+ SOA? foo. (21)
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 004b 557b 4000 4006 553b c0a8 010f d845 .KU{@.@.U;.....E
0x0020: f5f9 8115 0035 0c16 8cd1 fa0f 7bc6 8018 .....5......{...
0x0030: 01f6 9034 0000 0101 080a 8159 bc4f 5fc7 ...4.......Y.O_.
0x0040: 8205 0015 d8bf 0120 0001 0000 0000 0000 ................
0x0050: 0366 6f6f 0000 0600 01 .foo.....
10:29:08.031610 IP (tos 0x0, ttl 52, id 63950, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.33045: Flags [.], cksum 0x364b
(correct), seq 1, ack 24, win 227, options [nop,nop,TS val 1606910472
ecr 2170141775], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 f9ce 4000 3406 bcfe d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 8115 fa0f 7bc6 0c16 8ce8 8010 ...5....{.......
0x0030: 00e3 364b 0000 0101 080a 5fc7 8208 8159 ..6K......_....Y
0x0040: bc4f .O
10:29:08.031612 IP (tos 0x0, ttl 52, id 63951, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.33045: Flags [F.], cksum 0x364a
(correct), seq 1, ack 24, win 227, options [nop,nop,TS val 1606910472
ecr 2170141775], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 f9cf 4000 3406 bcfd d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 8115 fa0f 7bc6 0c16 8ce8 8011 ...5....{.......
0x0030: 00e3 364a 0000 0101 080a 5fc7 8208 8159 ..6J......_....Y
0x0040: bc4f .O
10:29:08.031613 IP (tos 0x0, ttl 52, id 63952, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.33045: Flags [R.], cksum 0x3646
(correct), seq 2, ack 24, win 227, options [nop,nop,TS val 1606910472
ecr 2170141775], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 f9d0 4000 3406 bcfc d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 8115 fa0f 7bc7 0c16 8ce8 8014 ...5....{.......
0x0030: 00e3 3646 0000 0101 080a 5fc7 8208 8159 ..6F......_....Y
0x0040: bc4f .O
10:29:08.032044 IP (tos 0x0, ttl 64, id 36109, offset 0, flags [DF],
proto TCP (6), length 60)
192.168.1.15.41939 > 216.69.245.249.53: Flags [S], cksum 0x9025
(incorrect -> 0x902c), seq 1780146441, win 64240, options [mss
1460,sackOK,TS val 2170141797 ecr 0,nop,wscale 7], length 0
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 003c 8d0d 4000 4006 1db8 c0a8 010f d845 .<..@.@........E
0x0020: f5f9 a3d3 0035 6a1a e109 0000 0000 a002 .....5j.........
0x0030: faf0 9025 0000 0204 05b4 0402 080a 8159 ...%...........Y
0x0040: bc65 0000 0000 0103 0307 .e........
10:29:08.056218 IP (tos 0x0, ttl 52, id 0, offset 0, flags [DF], proto
TCP (6), length 60)
216.69.245.249.53 > 192.168.1.15.41939: Flags [S.], cksum 0xf9a2
(correct), seq 3865991176, ack 1780146442, win 28960, options [mss
1460,sackOK,TS val 1606910474 ecr 2170141797,nop,wscale 7], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 003c 0000 4000 3406 b6c5 d845 f5f9 c0a8 .<..@.4....E....
0x0020: 010f 0035 a3d3 e66e 5808 6a1a e10a a012 ...5...nX.j.....
0x0030: 7120 f9a2 0000 0204 05b4 0402 080a 5fc7 q............._.
0x0040: 820a 8159 bc65 0103 0307 ...Y.e....
10:29:08.056262 IP (tos 0x0, ttl 64, id 36110, offset 0, flags [DF],
proto TCP (6), length 52)
192.168.1.15.41939 > 216.69.245.249.53: Flags [.], cksum 0x901d
(incorrect -> 0x9781), seq 1, ack 1, win 502, options [nop,nop,TS val
2170141821 ecr 1606910474], length 0
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 0034 8d0e 4000 4006 1dbf c0a8 010f d845 .4..@.@........E
0x0020: f5f9 a3d3 0035 6a1a e10a e66e 5809 8010 .....5j....nX...
0x0030: 01f6 901d 0000 0101 080a 8159 bc7d 5fc7 ...........Y.}_.
0x0040: 820a ..
10:29:08.056400 IP (tos 0x0, ttl 64, id 36111, offset 0, flags [DF],
proto TCP (6), length 75)
192.168.1.15.41939 > 216.69.245.249.53: Flags [P.], cksum 0x9034
(incorrect -> 0x9292), seq 1:24, ack 1, win 502, options [nop,nop,TS val
2170141821 ecr 1606910474], length 23 35268+ SOA? foo. (21)
0x0000: 88ef 165e 7d80 002b 67b8 1dda 0800 4500 ...^}..+g.....E.
0x0010: 004b 8d0f 4000 4006 1da7 c0a8 010f d845 .K..@.@........E
0x0020: f5f9 a3d3 0035 6a1a e10a e66e 5809 8018 .....5j....nX...
0x0030: 01f6 9034 0000 0101 080a 8159 bc7d 5fc7 ...4.......Y.}_.
0x0040: 820a 0015 89c4 0120 0001 0000 0000 0000 ................
0x0050: 0366 6f6f 0000 0600 01 .foo.....
10:29:08.077181 IP (tos 0x0, ttl 52, id 55813, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.41939: Flags [.], cksum 0x987b
(correct), seq 1, ack 24, win 227, options [nop,nop,TS val 1606910476
ecr 2170141821], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 da05 4000 3406 dcc7 d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 a3d3 e66e 5809 6a1a e121 8010 ...5...nX.j..!..
0x0030: 00e3 987b 0000 0101 080a 5fc7 820c 8159 ...{......_....Y
0x0040: bc7d .}
10:29:08.077183 IP (tos 0x0, ttl 52, id 55814, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.41939: Flags [F.], cksum 0x987a
(correct), seq 1, ack 24, win 227, options [nop,nop,TS val 1606910476
ecr 2170141821], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 da06 4000 3406 dcc6 d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 a3d3 e66e 5809 6a1a e121 8011 ...5...nX.j..!..
0x0030: 00e3 987a 0000 0101 080a 5fc7 820c 8159 ...z......_....Y
0x0040: bc7d .}
10:29:08.077184 IP (tos 0x0, ttl 52, id 55815, offset 0, flags [DF],
proto TCP (6), length 52)
216.69.245.249.53 > 192.168.1.15.41939: Flags [R.], cksum 0x9876
(correct), seq 2, ack 24, win 227, options [nop,nop,TS val 1606910476
ecr 2170141821], length 0
0x0000: 002b 67b8 1dda 88ef 165e 7d80 0800 4500 .+g......^}...E.
0x0010: 0034 da07 4000 3406 dcc5 d845 f5f9 c0a8 .4..@.4....E....
0x0020: 010f 0035 a3d3 e66e 580a 6a1a e121 8014 ...5...nX.j..!..
0x0030: 00e3 9876 0000 0101 080a 5fc7 820c 8159 ...v......_....Y
0x0040: bc7d .}



Bob Halley

unread,
Oct 19, 2023, 4:51:29 PM10/19/23
to dnspython-users
You didn't include the exception type or traceback, but from the behavior of dig, the empty string form, and the tcpdump, I'd say you're seeing EOFError thrown from dns.query's _net_read() function.  This means that that the other end closed the socket before a full response was written.  In your tcpdump you can see the far end doing a FIN and then a RST, which would cause the EOFError when we saw the FIN.

Calling str() on an exception in python is a little quirky in that it doesn't print what the actual exception is, just the string value of the exception's arguments, so if you don't supply any, it can be confusing.  Dnspython's _net_read() just says 

    raise EOFError

and not

    raise EOFError("EOF")

so when you print it, you get the empty string.  Exceptions without arguments are pretty common with Python code generally, so I always have my exception handlers do something like:

try:
    something_that_might_raise()
except Exception as e:
    print(f"caught {type(e)}: {e}")

So in this case you'd see something like

caught <class 'EOFError'>: 

and not the empty string.

You could also try explicitly catching EOFError and adding your own text.

Jeremy C. Reed

unread,
Oct 19, 2023, 6:19:10 PM10/19/23
to dnspython-users
Yes I should have looked at the traceback.

Thank you for the info.
I now looked at the type(e) and saw the <class 'EOFError'>

Reply all
Reply to author
Forward
0 new messages