Permanent 'Temporary failure in name resolution' after running for a number of hours

送分小仙女□ 提交于 2019-11-28 23:15:56

This was caused by a library's failure to close connections, leading to a large number of connections stuck in a CLOSE_WAIT state. Eventually this causes the 'Temporary failure in name resolution' error due to resource exhaustion.

Was experiencing the same issue, in my case it wasnt resource exhaustion, the problem for me happened when my dhcp server changed the nameserver address, libc did not want to play ball and reload the new resolv.conf file, maintaining the cached one and forcing me to restart the script every time it changed.

All my python socket connections attempts fail after this, so I found this code that solved the situation:

import ctypes
try:
    libc = ctypes.CDLL('libc.so.6')
    res_init = getattr(libc, '__res_init')
    res_init(None)
except:
    pass

Use it before calling the socket.connect, hope this helps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!