Skip to content

Commit

Permalink
* FIX [nng/core] prevent collateral damage of issue nanomq/nanomq#1411
Browse files Browse the repository at this point in the history
    This is not final fix.

Signed-off-by: JaylinYu <letrangerjaylin@gmail.com>
  • Loading branch information
JaylinYu committed Aug 15, 2023
1 parent ba49e03 commit a2061b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/core/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ int
nni_list_empty(nni_list *list)
{
// The first check ensures that we treat an uninitialized list

// as empty. This use useful for statically initialized lists.
return ((list->ll_head.ln_next == NULL) ||
(list->ll_head.ln_next == &list->ll_head));
Expand Down
17 changes: 12 additions & 5 deletions src/core/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pipe_destroy(void *arg)
if (p == NULL || p->cache) {
return;
}
// for a reaper bug
// if(p->guard != 1)
// return;

nni_pipe_run_cb(p, NNG_PIPE_EV_REM_POST);

Expand All @@ -59,14 +62,17 @@ pipe_destroy(void *arg)
}

// Freed here
struct subinfo * s = NULL;
struct subinfo *s = NULL;
while (!nni_list_empty(p->subinfol)) {
s = nni_list_last(p->subinfol);
nni_list_remove(p->subinfol, s);
nng_free(s->topic, strlen(s->topic));
nng_free(s, sizeof(*s));
if (s && s->topic != NULL) {
nni_list_remove(p->subinfol, s);
nng_free(s->topic, strlen(s->topic));
nng_free(s, sizeof(*s));
}
}
nni_free(p->subinfol, sizeof(nni_list));
if (p->subinfol != NULL)
nni_free(p->subinfol, sizeof(nni_list));

#ifdef NNG_ENABLE_STATS
nni_stat_unregister(&p->st_root);
Expand Down Expand Up @@ -255,6 +261,7 @@ pipe_create(nni_pipe **pp, nni_sock *sock, nni_sp_tran *tran, void *tran_data)
return (NNG_ENOMEM);
}

// p->guard = 1;
p->p_size = sz;
p->p_proto_data = p + 1;
p->p_tran_ops = *tran->tran_pipe;
Expand Down
1 change: 1 addition & 0 deletions src/core/sockimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct subinfo {

struct nni_pipe {
uint32_t p_id;
// uint32_t guard;
nni_sp_pipe_ops p_tran_ops;
nni_proto_pipe_ops p_proto_ops;
size_t p_size;
Expand Down
6 changes: 2 additions & 4 deletions src/sp/protocol/mqtt/nmq_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ nano_pipe_stop(void *arg)
return; // your time is yet to come

log_trace(" ########## nano_pipe_stop ########## ");
nni_aio_abort(&p->aio_send, NNG_ECANCELED);
nni_aio_stop(&p->aio_send);
nni_aio_stop(&p->aio_timer);
nni_aio_stop(&p->aio_recv);
Expand All @@ -575,7 +576,6 @@ nano_pipe_fini(void *arg)
nni_aio_set_msg(&p->aio_send, NULL);
nni_msg_free(msg);
}

void *nano_qos_db = p->pipe->nano_qos_db;

//Safely free the msgs in qos_db
Expand Down Expand Up @@ -1026,10 +1026,8 @@ nano_pipe_recv_cb(void *arg)
bool is_sqlite = s->conf->sqlite.enable;

if ((rv = nni_aio_result(&p->aio_recv)) != 0) {
// unexpected disconnect
nni_mtx_lock(&p->lk);
// unexpected disconnect, dont mind the TSAN here
p->reason_code = rv;
nni_mtx_unlock(&p->lk);
nni_pipe_close(p->pipe);
return;
}
Expand Down

0 comments on commit a2061b3

Please sign in to comment.