You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ii...@apache.org on 2019/08/16 10:32:23 UTC

[couchdb] branch master updated: Do not fail 'dev/run' on connection close

This is an automated email from the ASF dual-hosted git repository.

iilyak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new f2724d3  Do not fail 'dev/run' on connection close
     new 18bda46  Merge pull request #2105 from cloudant/improve-admin-part-setup
f2724d3 is described below

commit f2724d3fe19f58bca8c81b2ae610c6dd1c7e44c8
Author: ILYA Khlopotov <ii...@apache.org>
AuthorDate: Mon Aug 12 05:18:55 2019 -0700

    Do not fail 'dev/run' on connection close
    
    Sometimes admin party mode causes the 'dev/run' to fail with
    ```
    http.client.RemoteDisconnected: Remote end closed connection without response
    ```
    
    This PR makes this use case more robust.
---
 dev/run | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/dev/run b/dev/run
index 60e7d5c..10351eb 100755
--- a/dev/run
+++ b/dev/run
@@ -690,27 +690,37 @@ def generate_cookie():
 
 
 def cluster_setup_with_admin_party(ctx):
+    connect_nodes(ctx)
+    host, port = "127.0.0.1", cluster_port(ctx, 1)
+    create_system_databases(host, port)
+
+
+def connect_nodes(ctx):
     host, port = "127.0.0.1", backend_port(ctx, 1)
     for node in ctx["nodes"]:
-        body = "{}"
-        conn = httpclient.HTTPConnection(host, port)
-        conn.request("PUT", "/_nodes/%s@127.0.0.1" % node, body)
-        resp = conn.getresponse()
-        if resp.status not in (200, 201, 202, 409):
-            print(("Failed to join %s into cluster: %s" % (node, resp.read())))
-            sys.exit(1)
-    create_system_databases(host, cluster_port(ctx, 1))
+        path = "/_nodes/%s@127.0.0.1" % node
+        try_request(
+            host,
+            port,
+            "PUT",
+            path,
+            (200, 201, 202, 409),
+            body="{}",
+            error="Failed to join %s into cluster:\n" % node,
+        )
 
 
-def try_request(host, port, meth, path, success_codes, retries=10, retry_dt=1):
+def try_request(
+    host, port, meth, path, success_codes, body=None, retries=10, retry_dt=1, error=""
+):
     while True:
         conn = httpclient.HTTPConnection(host, port)
-        conn.request(meth, path)
+        conn.request(meth, path, body=body)
         resp = conn.getresponse()
         if resp.status in success_codes:
             return resp.status, resp.read()
         elif retries <= 0:
-            assert resp.status in success_codes, resp.read()
+            assert resp.status in success_codes, "%s%s" % (error, resp.read())
         retries -= 1
         time.sleep(retry_dt)
 
@@ -721,7 +731,14 @@ def create_system_databases(host, port):
         conn.request("HEAD", "/" + dbname)
         resp = conn.getresponse()
         if resp.status == 404:
-            try_request(host, port, "PUT", "/" + dbname, (201, 202, 412))
+            try_request(
+                host,
+                port,
+                "PUT",
+                "/" + dbname,
+                (201, 202, 412),
+                error="Failed to create '%s' database:\n" % dbname,
+            )
 
 
 @log(