oneclick: Do not use a stale Zulip client.

Initializing the Zulip client opens a long-lived TCP connection due to
connection pooling in urllib3.  In Github Actions, the network kills
such requests after ~270s, making the later `send_message` call fail.

Use a singular call to `zulip.Client()` early on to verify the
credentials, and do not cache the resulting client object.  Instead,
re-create it during the final step when it is needed, so we do not run
afoul of bad TCP connection state.

This would ideally be fixed via connection keepalive or retry at the
level of the Zulip module.
This commit is contained in:
Alex Vandiver 2022-05-12 03:19:07 -07:00 committed by Tim Abbott
parent c341414c60
commit ff647dff03
1 changed files with 5 additions and 2 deletions

View File

@ -10,7 +10,10 @@ from requests.adapters import HTTPAdapter
from urllib3.util import Retry from urllib3.util import Retry
manager = digitalocean.Manager(token=os.environ["DIGITALOCEAN_API_KEY"]) manager = digitalocean.Manager(token=os.environ["DIGITALOCEAN_API_KEY"])
zulip_client = zulip.Client() # We just temporarily create the client now, to validate that we can
# auth to the server; reusing it after the whole install fails because
# the connection has been half-closed in a way that breaks it.
zulip.Client()
TEST_DROPLET_SUBDOMAIN = "do" TEST_DROPLET_SUBDOMAIN = "do"
@ -126,7 +129,7 @@ def send_message(content: str) -> None:
"topic": "digitalocean installer", "topic": "digitalocean installer",
"content": content, "content": content,
} }
zulip_client.send_message(request) zulip.Client().send_message(request)
if __name__ == "__main__": if __name__ == "__main__":