Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete bridge switch fix #1146

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions src/mqtt/transport/quic/mqtt_quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct mqtt_quictran_pipe {
nni_lmq rslmq; // resend lmq
nni_lmq rxlmq; // recv lmq, shared by all streams
nni_mtx mtx;
bool closed;
nni_atomic_bool closed;
bool busy;
#ifdef NNG_HAVE_MQTT_BROKER
nni_msg *connack;
Expand Down Expand Up @@ -156,9 +156,8 @@ mqtt_quictran_pipe_close(void *arg)
mqtt_quictran_pipe *p = arg;

nng_stream_close(p->conn);
nni_atomic_set_bool(&p->closed, true);
nni_mtx_lock(&p->mtx);

p->closed = true;
for (uint8_t i = 0; i < QUIC_SUB_STREAM_NUM; i++)
{
quic_substream *stream = &p->substreams[i];
Expand Down Expand Up @@ -203,7 +202,8 @@ mqtt_quictran_pipe_init(void *arg, nni_pipe *npipe)
nni_lmq_init(&p->rslmq, 1024);
nni_lmq_init(&p->rxlmq, 1024);
p->busy = false;
p->closed = false;
nni_atomic_init_bool(&p->closed);
nni_atomic_set_bool(&p->closed, false);
// set max value by default
p->packmax == 0 ? p->packmax = (uint32_t)0xFFFFFFFF : p->packmax;
p->qosmax == 0 ? p->qosmax = 2 : p->qosmax;
Expand Down Expand Up @@ -569,7 +569,7 @@ mqtt_quictran_share_qos_send_cb(void *arg, nni_aio *qsaio, quic_substream *strea
int rv;

msg = nni_aio_get_msg(qsaio);
if (p->closed) {
if (nni_atomic_get_bool(&p->closed)) {
if (msg != NULL)
nni_msg_free(msg);
return;
Expand Down Expand Up @@ -785,13 +785,13 @@ mqtt_share_pipe_recv_cb(void *arg, nni_aio *rxaio, quic_substream *stream, nni_m
log_info("aio error result %s stream %p", nng_strerror(rv), stream);
if (stream == NULL) {
// set close flag to prevent infinit stream recv
p->closed = true;
nni_atomic_set_bool(&p->closed, true);
// NNI_ASSERT(rv == NNG_ECANCELED);
rv = NNG_ECONNABORTED;
}
goto recv_error;
}
if (p->closed) {
if (nni_atomic_get_bool(&p->closed)) {
goto recv_error;
}
uint16_t *id;
Expand Down Expand Up @@ -1083,7 +1083,7 @@ mqtt_share_pipe_recv_cb(void *arg, nni_aio *rxaio, quic_substream *stream, nni_m
recv_error:
if (aio)
nni_aio_list_remove(aio);
else if (!p->closed) {
else if (!nni_atomic_get_bool(&p->closed)) {
nni_iov sub_iov;
if (stream) {
// nni_msleep(500);
Expand Down Expand Up @@ -1118,7 +1118,7 @@ mqtt_quictran_pipe_send_prior(mqtt_quictran_pipe *p, nni_aio *aio)
int niov;
nni_iov iov[3];

if (p->closed) {
if (nni_atomic_get_bool(&p->closed)) {
nni_aio_finish_error(aio, SERVER_SHUTTING_DOWN);
return;
}
Expand Down Expand Up @@ -1199,7 +1199,7 @@ mqtt_quictran_pipe_send_start(mqtt_quictran_pipe *p)
int niov;
nni_iov iov[3];

if (p->closed) {
if (nni_atomic_get_bool(&p->closed)) {
while ((aio = nni_list_first(&p->sendq)) != NULL) {
nni_list_remove(&p->sendq, aio);
nni_aio_finish_error(aio, SERVER_SHUTTING_DOWN);
Expand Down Expand Up @@ -1268,6 +1268,10 @@ mqtt_quictran_pipe_send(void *arg, nni_aio *aio)
mqtt_quictran_pipe *p = arg;
int rv;

if (nni_atomic_get_bool(&p->closed)) {
nni_aio_finish_error(aio, NNG_ECLOSED);
return;
}
nni_mtx_lock(&p->mtx);
// Priority msg
int *flags = nni_aio_get_prov_data(aio);
Expand Down Expand Up @@ -1322,7 +1326,7 @@ mqtt_quictran_pipe_recv_start(mqtt_quictran_pipe *p, nni_aio *aio)
{
nni_iov iov;

if (p->closed) {
if (nni_atomic_get_bool(&p->closed)) {
while ((aio = nni_list_first(&p->recvq)) != NULL) {
nni_list_remove(&p->recvq, aio);
nni_aio_finish_error(aio, NNG_ECONNABORTED);
Expand Down Expand Up @@ -1794,6 +1798,10 @@ mqtt_quictran_ep_connect(void *arg, nni_aio *aio)
log_error("ep connect rv %d", rv);
return;
}
if (ep->closed) {
nni_aio_finish_error(aio, NNG_ECLOSED);
return;
}
if (ep->backoff != 0) {
ep->backoff = ep->backoff * 2;
ep->backoff = ep->backoff > ep->backoff_max
Expand Down Expand Up @@ -1929,7 +1937,7 @@ mqtt_quictran_ep_set_ep_closed(void *arg, const void *v, size_t sz, nni_opt_type
if (tmp == true) {
mqtt_quictran_pipe *p;
NNI_LIST_FOREACH (&ep->busypipes, p) {
mqtt_quictran_pipe_close(p);
nni_pipe_close(p->npipe);
}
}
nni_mtx_unlock(&ep->mtx);
Expand Down
2 changes: 1 addition & 1 deletion src/mqtt/transport/tcp/mqtt_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ mqtt_tcptran_pipe_send(void *arg, nni_aio *aio)
return;
}
if (nni_atomic_get_bool(&p->closed)) {
nni_aio_finish_error(aio, rv);
nni_aio_finish_error(aio, NNG_ECLOSED);
return;
}
nni_mtx_lock(&p->mtx);
Expand Down
5 changes: 2 additions & 3 deletions src/mqtt/transport/tls/mqtt_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,12 +949,11 @@ mqtts_tcptran_pipe_send(void *arg, nni_aio *aio)
return;
}
if (nni_atomic_get_bool(&p->closed)) {
nni_aio_finish_error(aio, rv);
nni_aio_finish_error(aio, NNG_ECLOSED);
return;
}
nni_mtx_lock(&p->mtx);
if ((rv = nni_aio_schedule(aio, mqtts_tcptran_pipe_send_cancel, p)) !=
0) {
if ((rv = nni_aio_schedule(aio, mqtts_tcptran_pipe_send_cancel, p)) != 0) {
nni_mtx_unlock(&p->mtx);
nni_aio_finish_error(aio, rv);
return;
Expand Down
Loading