diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index 4ccf73b4370daf82790b64afb1d3332ce1566d61..a4ccc6c04dd39988be708b0eb2768c447d54ec48 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -372,10 +372,11 @@ failed1:
  * host:	host header to send to the new server
  */
 LWS_VISIBLE struct lws *
-lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
+lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port,
 		 const char *path, const char *host)
 {
 	char origin[300] = "", protocol[300] = "", method[32] = "", *p;
+	struct lws *wsi = *pwsi;
 
 	if (wsi->u.hdr.redirects == 3) {
 		lwsl_err("%s: Too many redirects\n", __func__);
@@ -444,7 +445,9 @@ lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
 	if (lws_hdr_simple_create(wsi, _WSI_TOKEN_CLIENT_URI, origin))
 		return NULL;
 
-	return lws_client_connect_2(wsi);
+	*pwsi = lws_client_connect_2(wsi);
+
+	return *pwsi;
 }
 
 #ifdef LWS_WITH_HTTP_PROXY
diff --git a/lib/client.c b/lib/client.c
index b5d8614a0ec2e74187387ee4d61cfd3d56bb710a..fa162170ed7b845a1d68780ec2009c7046fe0728 100755
--- a/lib/client.c
+++ b/lib/client.c
@@ -483,10 +483,19 @@ lws_client_interpret_server_handshake(struct lws *wsi)
 		if (!strcmp(prot, "wss") || !strcmp(prot, "https"))
 			ssl = 1;
 
-		if (!lws_client_reset(wsi, ssl, ads, port, path, ads)) {
+		if (!lws_client_reset(&wsi, ssl, ads, port, path, ads)) {
+			/* there are two ways to fail out with NULL return...
+			 * simple, early problem where the wsi is intact, or
+			 * we went through with the reconnect attempt and the
+			 * wsi is already closed.  In the latter case, the wsi
+			 * has beet set to NULL additionally.
+			 */
 			lwsl_err("Redirect failed\n");
 			cce = "HS: Redirect failed";
-			goto bail3;
+			if (wsi)
+				goto bail3;
+
+			return 1;
 		}
 		return 0;
 	}
diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
index 21ffc3ab30ae136c7ef2a710eb93225bf67fb48e..a2abb2b64fe0b25cde374fb9f7725c4728635944 100644
--- a/lib/private-libwebsockets.h
+++ b/lib/private-libwebsockets.h
@@ -1616,7 +1616,7 @@ LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_client_connect_2(struct lws *wsi);
 
 LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT
-lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
+lws_client_reset(struct lws **wsi, int ssl, const char *address, int port,
 		 const char *path, const char *host);
 
 LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT