Skip to content

Commit

Permalink
Merge pull request #492 from openziti/fix-crash-during-channel-discon…
Browse files Browse the repository at this point in the history
…nect

guard against re-entering on_channel_close()
  • Loading branch information
ekoby authored Feb 24, 2023
2 parents 1ded349 + b698826 commit c74ab09
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions library/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ int ziti_channel_close(ziti_channel_t *ch, int err) {
if (ch->state != Closed) {
CH_LOG(INFO, "closing[%s]", ch->name);

ch->state = Closed;
on_channel_close(ch, err, 0);
ch->state = Closed;

uv_close((uv_handle_t *) ch->timer, (uv_close_cb) free);
ch->timer = NULL;
Expand Down Expand Up @@ -738,12 +738,14 @@ static void reconnect_channel(ziti_channel_t *ch, bool now) {
static void on_channel_close(ziti_channel_t *ch, int ziti_err, ssize_t uv_err) {
ziti_context ztx = ch->ctx;

if (ch->state != Closed) {
if (ch->state == Connected) {
ch->notify_cb(ch, EdgeRouterDisconnected, ch->notify_ctx);
}
ch->state = Disconnected;
if (ch->state == Closed || ch->state == Disconnected) {
return;
}

if (ch->state == Connected) {
ch->notify_cb(ch, EdgeRouterDisconnected, ch->notify_ctx);
}
ch->state = Disconnected;

ch->latency = UINT64_MAX;
if (uv_is_active((const uv_handle_t *) &ch->timer)) {
Expand Down

0 comments on commit c74ab09

Please sign in to comment.