1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-04-01 21:27:22 +02:00

race condition between backups and status checks - connection refused

At the end of the backup, wait a bit for dovecot and postfix to finish restarting.

Hopefully fixes #381.
This commit is contained in:
Joshua Tauberer
2015-04-29 21:06:38 +00:00
parent c03e00035f
commit febfa72d60
2 changed files with 24 additions and 1 deletions

View File

@@ -184,3 +184,19 @@ def du(path):
seen.add(stat.st_ino)
total_size += stat.st_size
return total_size
def wait_for_service(port, public, env, timeout):
# Block until a service on a given port (bound privately or publicly)
# is taking connections, with a maximum timeout.
import socket, time
start = time.perf_counter()
while True:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout/3)
try:
s.connect(("127.0.0.1" if not public else env['PUBLIC_IP'], port))
return True
except OSError:
if time.perf_counter() > start+timeout:
return False
time.sleep(min(timeout/4, 1))