1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

wait_for: treat broken connections as "unready" (#28839)

* wait_for: treat broken connections as "unready"

We have observed the following condition while waiting for hosts:

```
Traceback (most recent call last):
  File "/var/folders/f8/23xp00654plcv2b2tcc028680000gn/T/ansible_8hxm4_/ansible_module_wait_for.py", line 585, in <module>
    main()
  File "/var/folders/f8/23xp00654plcv2b2tcc028680000gn/T/ansible_8hxm4_/ansible_module_wait_for.py", line 535, in main
    s.shutdown(socket.SHUT_RDWR)
  File "/usr/local/opt/python/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 228, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 57] Socket is not connected
```

This appears to happen while the host is still starting; we believe something is
accepting our connection but immediately resetting it. In these cases, we'd
prefer to continue waiting instead of immediately failing the play.

This patch has been applied locally for some time, and we have seen no adverse
effects.

* wait_for: fixup change

We were missing an import and a space after the `#`
This commit is contained in:
sethp-nr 2017-10-12 08:37:20 -07:00 committed by Brian Coca
parent 79f2cfbcf9
commit 402b095841

View file

@ -168,6 +168,7 @@ EXAMPLES = r'''
import binascii import binascii
import datetime import datetime
import errno
import math import math
import os import os
import re import re
@ -558,15 +559,27 @@ def main():
break break
# Shutdown the client socket # Shutdown the client socket
s.shutdown(socket.SHUT_RDWR) try:
s.close() s.shutdown(socket.SHUT_RDWR)
except socket.error as e:
if e.errno != errno.ENOTCONN:
raise
# else, the server broke the connection on its end, assume it's not ready
else:
s.close()
if matched: if matched:
# Found our string, success! # Found our string, success!
break break
else: else:
# Connection established, success! # Connection established, success!
s.shutdown(socket.SHUT_RDWR) try:
s.close() s.shutdown(socket.SHUT_RDWR)
except socket.error as e:
if e.errno != errno.ENOTCONN:
raise
# else, the server broke the connection on its end, assume it's not ready
else:
s.close()
break break
# Conditions not yet met, wait and try again # Conditions not yet met, wait and try again