Skip to content

Commit 7b86412

Browse files
committed
he-debug
1 parent bd9365a commit 7b86412

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

lib/core-net/client/connect3.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ lws_client_happy_eyeballs_cb(lws_sorted_usec_list_t *sul)
6969
struct lws *wsi = lws_container_of(sul, struct lws,
7070
sul_happy_eyeballs);
7171

72-
lwsl_wsi_info(wsi, "happy eyeballs timer fired, initiating parallel connect");
72+
lwsl_wsi_notice(wsi, "happy eyeballs timer fired, initiating parallel connect");
7373
lws_client_connect_3_connect(wsi, NULL, NULL, 0, NULL);
7474
}
7575

@@ -578,6 +578,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
578578
}
579579
lws_sul_cancel(&wsi->sul_happy_eyeballs);
580580
if (pidx != -1) {
581+
lwsl_wsi_notice(wsi, "racing connect %d won, promoting", pidx);
581582
/*
582583
* A racing connect won. The primary
583584
* socket is still open and still in the
@@ -640,7 +641,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
640641
lws_snprintf(dcce, sizeof(dcce), "conn fail: %s",
641642
lws_errno_describe(real_errno, t16, sizeof(t16)));
642643
cce = dcce;
643-
lwsl_wsi_debug(wsi, "%s", dcce);
644+
lwsl_wsi_notice(wsi, "%s", dcce);
644645
lws_metrics_caliper_report(wsi->cal_conn, METRES_NOGO);
645646

646647
if (pidx != -1) {
@@ -674,6 +675,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
674675
* kernel recycles the fd
675676
* numbers.
676677
*/
678+
lwsl_wsi_notice(wsi, "primary failed, promoting parallel racer %d", m);
677679
if (wsi->a.context->event_loop_ops->promote_parallel)
678680
wsi->a.context->event_loop_ops->promote_parallel(wsi, m);
679681
promote_parallel_fd(wsi, m);
@@ -1081,7 +1083,8 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
10811083
char buf[64];
10821084

10831085
lws_sa46_write_numeric_address((lws_sockaddr46 *)psa, buf, sizeof(buf));
1084-
lwsl_wsi_info(wsi, "trying %s", buf);
1086+
lwsl_wsi_notice(wsi, "trying %s%s", buf,
1087+
is_parallel ? " (parallel racer)" : "");
10851088
}
10861089

10871090
#if defined(LWS_WITH_SYS_FAULT_INJECTION)
@@ -1180,6 +1183,8 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
11801183
}
11811184
#endif
11821185
#endif
1186+
if (is_parallel)
1187+
lwsl_wsi_notice(wsi, "parallel racer failed connect() synchronously");
11831188
goto try_next_dns_result_fds;
11841189
}
11851190

@@ -1311,6 +1316,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
13111316

13121317
if (is_parallel) {
13131318
/* promote parallel to primary right away */
1319+
lwsl_wsi_notice(wsi, "parallel racer %d connected synchronously, promoting", pidx);
13141320
wsi->parallel_conns[pidx].position_in_fds_table = wsi->position_in_fds_table;
13151321
wsi->position_in_fds_table = saved_pos;
13161322
wsi->desc = saved_fd;
@@ -1412,7 +1418,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
14121418
wsi->a.protocol->callback(wsi, LWS_CALLBACK_WSI_CREATE,
14131419
wsi->user_space, NULL, 0);
14141420

1415-
lwsl_wsi_debug(wsi, "going into connect_4");
1421+
lwsl_wsi_notice(wsi, "going into connect_4");
14161422

14171423
return lws_client_connect_4_established(wsi, NULL, plen);
14181424

@@ -1518,6 +1524,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads,
15181524
}
15191525
if (any_valid) {
15201526
/* some connection is still running */
1527+
lwsl_wsi_notice(wsi, "attempt failed, others still running");
15211528
return wsi;
15221529
}
15231530
}

lib/core-net/close.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,8 +818,11 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
818818
!wsi->close_is_redirect) {
819819
static const char _reason[] = "closed before established";
820820

821-
lwsl_wsi_debug(wsi, "closing in unestablished state 0x%x",
822-
lwsi_state(wsi));
821+
lwsl_wsi_notice(wsi, "closing in unestablished state 0x%x "
822+
"(fd %d, parallels %d, redirect %d)",
823+
lwsi_state(wsi),
824+
(int)wsi->desc.sockfd, wsi->parallel_count,
825+
wsi->close_is_redirect);
823826
wsi->socket_is_permanently_unusable = 1;
824827

825828
lws_inform_client_conn_fail(wsi,

lib/roles/h1/ops-h1.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,23 @@ rops_handle_POLLIN_h1(struct lws_context_per_thread *pt, struct lws *wsi,
789789
#endif
790790

791791
if (lwsi_state(wsi) == LRS_WAITING_CONNECT &&
792-
(pollfd->revents & LWS_POLLHUP))
793-
return LWS_HPI_RET_PLEASE_CLOSE_ME;
792+
(pollfd->revents & LWS_POLLHUP)) {
793+
/*
794+
* This fd's connect attempt failed. But if we are racing
795+
* parallel connect attempts, the failing fd may only be the
796+
* primary while a racer is still live and able to win.
797+
*
798+
* Let connect_3 disposition the failed attempt (promoting a
799+
* live racer, or trying the next dns result, or informing
800+
* the connect failure if nothing is left) rather than
801+
* killing the whole wsi here.
802+
*/
803+
if (!lws_client_connect_3_connect(wsi, NULL, NULL, 0, pollfd))
804+
/* the wsi was synchronously closed and freed */
805+
return LWS_HPI_RET_WSI_ALREADY_DIED;
806+
807+
return LWS_HPI_RET_HANDLED;
808+
}
794809

795810
return LWS_HPI_RET_HANDLED;
796811
}

lib/roles/http/client/client-http.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ lws_http_client_socket_service(struct lws *wsi, struct lws_pollfd *pollfd)
7171
* we are under PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE
7272
* timeout protection set in client-handshake.c
7373
*/
74-
if (pollfd->revents & LWS_POLLOUT)
74+
/*
75+
* A hangup or error here means this fd's attempt failed;
76+
* disposition it via connect_3 so any parallel racing
77+
* attempt on the same wsi can still be promoted instead of
78+
* being lost when the wsi is killed
79+
*/
80+
if (pollfd->revents & (LWS_POLLOUT | LWS_POLLHUP))
7581
if (lws_client_connect_3_connect(wsi, NULL, NULL, 0, pollfd) == NULL) {
7682
lwsl_client("closed\\n");
7783
return LWS_HPI_RET_WSI_ALREADY_DIED;

0 commit comments

Comments
 (0)