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

后端 未结 2 838
故里飘歌
故里飘歌 2020-12-15 06:21

After running for a number of hours on Linux, my Python 2.6 program that uses urllib2, httplib and threads, starts raising this error for every request:

相关标签:
2条回答
  • 2020-12-15 06:32

    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

    0 讨论(0)
  • 2020-12-15 06:53

    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.

    0 讨论(0)
提交回复
热议问题