Open mtomaska opened 2 years ago
Thanks for great bug report. I think pinpointed problem to greendns.HostsResolver.query
. Not sure what's proper solution yet.
FYI: you can't reliably undo monkey patch, but it doesn't change test result.
Note to contributor or myself: start with tests/isolated/greendns_getaddrinfo.py
like this
__test__ = False
def fun(family=0, flags=0):
try:
addrinfo = socket.getaddrinfo(host="localhost", port=None, family=family, flags=flags)
except IOError as err:
return "error: {}".format(err)
return str(addrinfo)
if __name__ == "__main__":
import socket
configs = [
("default", dict()),
("AF_UNSPEC", dict(family=socket.AF_UNSPEC)),
("AI_CANONNAME", dict(flags=socket.AI_CANONNAME)),
]
results_stdlib = [(tag, fun(**kwargs)) for tag, kwargs in configs]
import eventlet
eventlet.monkey_patch()
results_patched = [(tag, fun(**kwargs)) for tag, kwargs in configs]
for stdlib, patched in zip(results_stdlib, results_patched, strict=True):
assert patched == stdlib, "{}\t{}".format(*patched)
print("pass")
For what is worth. The reason that /etc/hosts content is not queried is because greendns.py#L388 rdtype in _hosts_rdtypes
evaluates to False
because rdtype
in my case is AI_CANONNAME
I believe I would get my result if that condition was True
. But I dont understand the code enough to judge if thats a proper fix or not.
And thanks for the heads up about monkey_patch undo. I was not sure if there was a proper way or not, so I just tried reload
@temoto as a workaround, is there a safe way to use socket.getaddrinfo()
from python standard library while keeping other socket methods patched by eventlet? Thanks
eventlet.patcher.original("socket")
is the supported way to access
unmodified modules.
Sorry for the inconvenience.
On Fri, Jul 8, 2022, 19:10 Miro @.***> wrote:
@temoto https://github.com/temoto as a workaround, is there a safe way to use socket.getaddrinfo() from python standard library while keeping other socket methods patched by eventlet? Thanks
— Reply to this email directly, view it on GitHub https://github.com/eventlet/eventlet/issues/764#issuecomment-1179155795, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAGTMLZJJBWKB7OCOLATNDVTBHINANCNFSM526YPFGQ . You are receiving this because you were mentioned.Message ID: @.***>
Version: Eventlet 0.33.1 (also confirmed in 0.30.3 just because it was available)
Its seems that greendns.py:getaddrinfo() seems to ignore looking into /etc/hosts when querying with
flags=socket.AI_CANONNAME
?Here is a simple reproducing code
Output:
I would expect that getaddrinfo() would return the same value as the one in socket standard library.