Comment 11 for bug 586359

So it looks like Xen guests sometimes ignore the first network packet. If we run the script below right after the builder is resumed it randomly prints the error message. We can work around this in the buildd-manager by sending a fake message right after the builder is resumed.

#!/usr/bin/env python
import errno
from socket import socket
import sys

def connect_to_server_until_timeout(host, port, max_tries=9999):
    for i in range(max_tries):
        if i % 1000 == 0:
            print i
        s = socket()
        result = s.connect_ex((host, port))
        if result == errno.ETIMEDOUT:
            if i == 0:
                print "First packet time out."
            else:
                raise RuntimeError("YAY, Timeout after %s tries" % (i,))
        if result == 0:
            s.close()

if __name__ == '__main__':
    server = sys.argv[1]
    print connect_to_server_until_timeout(server, 8221)