diff --git a/tunnels/client/reverse/helpers.h b/tunnels/client/reverse/helpers.h index dd1beb55..a451cbb3 100644 --- a/tunnels/client/reverse/helpers.h +++ b/tunnels/client/reverse/helpers.h @@ -53,7 +53,6 @@ static void cleanup(reverse_client_con_state_t *cstate) if (! cstate->idle_handle_removed) { reverse_client_state_t *state = STATE(cstate->self); - removeIdleItemByHash(cstate->u->tid, state->starved_connections, (hash_t) (cstate)); } doneLineDownSide(cstate->u); diff --git a/tunnels/client/reverse/reverse_client.c b/tunnels/client/reverse/reverse_client.c index bf671fa1..c7834df7 100644 --- a/tunnels/client/reverse/reverse_client.c +++ b/tunnels/client/reverse/reverse_client.c @@ -72,6 +72,13 @@ static void downStream(tunnel_t *self, context_t *c) initiateConnect(self, tid, false); atomic_fetch_add_explicit(&(state->reverse_cons), 1, memory_order_relaxed); + if (! ucstate->idle_handle_removed) + { + ucstate->idle_handle_removed = true; + reverse_client_state_t *state = STATE(ucstate->self); + removeIdleItemByHash(ucstate->u->tid, state->starved_connections, (hash_t) (ucstate)); + } + ucstate->pair_connected = true; lockLine(ucstate->d); self->dw->downStream(self->dw, newInitContext(ucstate->d)); @@ -159,9 +166,12 @@ static void downStream(tunnel_t *self, context_t *c) ucstate->established = true; initiateConnect(self, tid, false); - idle_item_t *con_idle_item = newIdleItem(state->starved_connections, (hash_t) (ucstate), ucstate, - onStarvedConnectionExpire, c->line->tid, kConnectionStarvationTimeOut); - (void)con_idle_item; + idle_item_t *con_idle_item = + newIdleItem(state->starved_connections, (hash_t) (ucstate), ucstate, onStarvedConnectionExpire, + c->line->tid, kConnectionStarvationTimeOut); + ucstate->idle_handle_removed = false; + + (void) con_idle_item; destroyContext(c); } else