Skip to content

Commit

Permalink
force session refresh if router closes edge connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ekoby committed Dec 18, 2020
1 parent 320e02b commit 6275f8b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ struct ziti_ctx {
extern "C" {
#endif

void ziti_force_session_refresh(ziti_context ztx);

int ziti_close_channels(ziti_context ztx);

int ziti_channel_connect(ziti_context ztx, const char *name, const char *url, ch_connect_cb, void *ctx);
Expand Down
21 changes: 14 additions & 7 deletions library/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,23 @@ static void async_write(uv_async_t *ar) {

static void reconnect_cb(uv_timer_t *t) {
ziti_channel_t *ch = t->data;
ziti_context ztx = ch->ctx;

ch->msg_seq = 0;
if(ztx->session == NULL || ztx->session->token == NULL) {
ZITI_LOG(ERROR, "ziti context is not authenticated, delaying re-connect");
reconnect_channel(ch);
} else {
ch->msg_seq = 0;

uv_connect_t *req = calloc(1, sizeof(uv_connect_t));
req->data = ch;
uv_connect_t *req = calloc(1, sizeof(uv_connect_t));
req->data = ch;

ch->state = Connecting;
ch->state = Connecting;

uv_mbed_init(ch->ctx->loop, &ch->connection, ch->ctx->tlsCtx);
ch->connection._stream.data = ch;
uv_mbed_connect(req, &ch->connection, ch->host, ch->port, on_channel_connect_internal);
uv_mbed_init(ch->ctx->loop, &ch->connection, ch->ctx->tlsCtx);
ch->connection._stream.data = ch;
uv_mbed_connect(req, &ch->connection, ch->host, ch->port, on_channel_connect_internal);
}
uv_close((uv_handle_t *) t, (uv_close_cb) free);
}

Expand Down Expand Up @@ -621,6 +627,7 @@ static void on_channel_close(ziti_channel_t *ch, ssize_t code) {

if (ch->state != Closed) {
reconnect_channel(ch);
ziti_force_session_refresh(ztx);
}
}

Expand Down
4 changes: 4 additions & 0 deletions library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ static void session_refresh(uv_timer_t *t) {
ziti_ctrl_current_api_session(&ztx->controller, session_cb, req);
}

void ziti_force_session_refresh(ziti_context ztx) {
uv_timer_start(&ztx->session_timer, session_refresh, 0, 0);
}

static void ziti_re_auth(ziti_context ztx) {
ZITI_LOG(WARN, "starting to re-auth with ctlr[%s]", ztx->opts->controller);
uv_timer_stop(&ztx->refresh_timer);
Expand Down

0 comments on commit 6275f8b

Please sign in to comment.