From 789d98b98be79ac89468b99b7f2c7760e803a9b5 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Thu, 25 Feb 2021 21:22:06 +0000 Subject: [PATCH] sspc: handle loss of proxy manifesting itself as 0 length rx If the client library loses the proxy connection, it can receive an endless stream of 0 length rx instead of understanding that the UDS peer has gone. Handle that correctly so the client reacts to the loss of the proxy link by trying to reacquire it. Adapt the sspc state to be suitable for retry in that case, by dropping any dsh and letting the logical ss know that he is DISCONNECTED, if he thought he was CONNECTED. --- lib/secure-streams/secure-streams-client.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/secure-streams/secure-streams-client.c b/lib/secure-streams/secure-streams-client.c index 3497855ac..91d9bd0c5 100644 --- a/lib/secure-streams/secure-streams-client.c +++ b/lib/secure-streams/secure-streams-client.c @@ -178,6 +178,13 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, lwsl_info("%s: LWS_CALLBACK_RAW_CLOSE: %s proxy conn down, sspc h %s\n", __func__, lws_wsi_tag(wsi), lws_sspc_tag(h)); if (h) { + lws_dsh_destroy(&h->dsh); + if (h->ss_dangling_connected && h->ssi.state) { + lwsl_notice("%s: setting _DISCONNECTED\n", __func__); + h->ss_dangling_connected = 0; + h->prev_ss_state = LWSSSCS_DISCONNECTED; + h->ssi.state(ss_to_userobj(h), NULL, LWSSSCS_DISCONNECTED, 0); + } h->cwsi = NULL; /* * schedule a reconnect in 1s @@ -200,6 +207,12 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason, return -1; } + if (!len) { + lwsl_notice("%s: RAW_RX: zero len\n", __func__); + + return -1; + } + n = lws_ss_deserialize_parse(&h->parser, lws_get_context(wsi), h->dsh, in, len, &h->state, h, (lws_ss_handle_t **)m, &h->ssi, 1);