[issue46116] _asyncio_backend.py datagram_received doesn't handle Future cancelled, throws Exception

2021-12-17 Thread James Lawrie


New submission from James Lawrie :

The datagram_received:

def datagram_received(self, data, addr):
if self.recvfrom:
self.recvfrom.set_result((data, addr))
self.recvfrom = None

Throws an exception if self.recvfrom is a Future Cancelled:

Exception in callback _SelectorDatagramTransport._read_ready()
handle: 
Traceback (most recent call last):
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 1021, in 
_read_ready
self._protocol.datagram_received(data, addr)
  File "/usr/local/lib/python3.8/dist-packages/dns/_asyncio_backend.py", line 
30, in datagram_received
self.recvfrom.set_result((data, addr))
asyncio.exceptions.InvalidStateError: invalid state

In my test code (attached), this wasn't caught in a try: catch:

--
components: asyncio
files: asynctest.py
messages: 408778
nosy: asvetlov, james2, yselivanov
priority: normal
severity: normal
status: open
title: _asyncio_backend.py datagram_received doesn't handle Future cancelled, 
throws Exception
versions: Python 3.8
Added file: https://bugs.python.org/file50500/asynctest.py

___
Python tracker 
<https://bugs.python.org/issue46116>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45683] dns.asyncresolver ignores nameserver parameter

2021-11-01 Thread James Lawrie


James Lawrie  added the comment:

Sorry. This was a pebkac error, I was setting nameserver instead of nameservers

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 
<https://bugs.python.org/issue45683>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45683] dns.asyncresolver ignores nameserver parameter

2021-11-01 Thread James Lawrie


New submission from James Lawrie :

The DNS async resolver allows you to specify a list of nameservers to use, but 
they are ignored and the system nameservers are used instead.

Test code below demonstrating the issue:

# cat test.py
import dns.asyncresolver
import asyncio
from pprint import pprint
 
 
async def main(domains):
results = await get_ips_bulk(domains)
results = [item for sublist in results for item in sublist]
pprint(results)
 
async def get_ips_bulk(domains):
output = [get_ips(domain) for domain in domains]
return await asyncio.gather(*output, return_exceptions=True)
 
async def get_ips(domain):
res = dns.asyncresolver.Resolver()
res.nameserver = ["1.1.1.1"]
results = []
try:
ipv4 = await res.resolve(domain, 'A')
for result in ipv4:
results.append(['A', domain, result.to_text()])
except:
results.append(['A', domain, 'n/a'])
try:
ipv6 = await res.resolve(domain, '')
results.append(['', domain, result.to_text()])
except:
results.append(['', domain, 'n/a'])
 
return results
  
domains = ['python.org']
asyncio.run(main(domains))
 

It should use 1.1.1.1 as the nameserver but watching tcpdump it's using 8.8.8.8 
per /etc/resolv.conf:

# tcpdump -n port 53 &
[1] 16751
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
# python3 test.py
19:05:02.750458 IP x.x.x.x.44173 > 8.8.8.8.53: 46143+ A? python.org. (28)
19:05:02.756265 IP 8.8.8.8.53 > x.x.x.x.44173: 46143 1/0/0 A 138.197.63.241 (44)
19:05:02.757392 IP x.x.x.x.37827 > 8.8.8.8.53: 17493+ ? python.org. (28)
19:05:02.765797 IP 8.8.8.8.53 > x.x.x.x.37827: 17493 0/1/0 (115)
[['A', 'python.org', '138.197.63.241'], ['', 'python.org', 'n/a']]
# fg
tcpdump -n port 53
^C
# grep -P "^nameserver" /etc/resolv.conf
nameserver 8.8.8.8

--
components: asyncio
messages: 405460
nosy: asvetlov, james2, yselivanov
priority: normal
severity: normal
status: open
title: dns.asyncresolver ignores nameserver parameter
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue45683>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com