Skip to content

Commit

Permalink
Fixes #1255: Introduce an activation lock to protect the raw connecti… (
Browse files Browse the repository at this point in the history
#1262)

* Fixes #1255: Introduce an activation lock to protect the raw connection from being activated when it is being torn down

* Moved the connection check before locking using activation lock in src/cutthrough_utils.c
  • Loading branch information
ganeshmurthy authored Oct 23, 2023
1 parent d74d9d0 commit bcbafec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/adaptors/tcp_lite/tcp_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ static void free_connection_IO(void *context)
sys_atomic_destroy(&conn->core_activation);
sys_atomic_destroy(&conn->raw_opened);
qd_timer_free(conn->close_timer);
sys_mutex_free(&conn->activation_lock);
free_tcplite_connection_t(conn);
}

Expand All @@ -406,7 +407,11 @@ static void close_raw_connection_XSIDE_IO(tcplite_connection_t *conn)
pn_raw_connection_close(conn->raw_conn);
drain_read_buffers_XSIDE_IO(conn->raw_conn);
drain_write_buffers_XSIDE_IO(conn->raw_conn);

sys_mutex_lock(&conn->activation_lock);
pn_raw_connection_set_context(conn->raw_conn, 0);
conn->raw_conn = 0;
sys_mutex_unlock(&conn->activation_lock);
}
}
}
Expand Down Expand Up @@ -1020,9 +1025,11 @@ static void handle_outbound_delivery_CSIDE(tcplite_connection_t *conn, qdr_link_
// It is not guaranteed that this function will be called on the proper IO thread. Wake the raw connection for
// continued processing in the correct context.
//
sys_mutex_lock(&conn->activation_lock);
if (IS_ATOMIC_FLAG_SET(&conn->raw_opened)) {
pn_raw_connection_wake(conn->raw_conn);
}
sys_mutex_unlock(&conn->activation_lock);
}


Expand Down Expand Up @@ -1349,6 +1356,7 @@ void on_accept(qd_adaptor_listener_t *listener, pn_listener_t *pn_listener, void
conn->common.context_type = TL_CONNECTION;
conn->common.parent = (tcplite_common_t*) li;

sys_mutex_init(&conn->activation_lock);
sys_atomic_init(&conn->core_activation, 0);
sys_atomic_init(&conn->raw_opened, 1);

Expand Down Expand Up @@ -1393,10 +1401,12 @@ static void CORE_activate(void *context, qdr_connection_t *core_conn)

case TL_CONNECTION:
conn = (tcplite_connection_t*) common;
sys_mutex_lock(&conn->activation_lock);
if (IS_ATOMIC_FLAG_SET(&conn->raw_opened)) {
SET_ATOMIC_FLAG(&conn->core_activation);
pn_raw_connection_wake(conn->raw_conn);
}
sys_mutex_unlock(&conn->activation_lock);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/tcp_lite/tcp_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ typedef struct tcplite_connection_t {
tcplite_common_t common;
DEQ_LINKS(tcplite_connection_t);
pn_raw_connection_t *raw_conn;
sys_mutex_t activation_lock;
sys_atomic_t core_activation;
sys_atomic_t raw_opened;
qd_timer_t *close_timer;
Expand Down
8 changes: 6 additions & 2 deletions src/cutthrough_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ static void activate_connection(qd_message_activation_t *activation, qd_directio

case QD_ACTIVATION_TCP: {
tcplite_connection_t *conn = safe_deref_tcplite_connection_t(activation->safeptr);
if (!!conn && IS_ATOMIC_FLAG_SET(&conn->raw_opened)) {
pn_raw_connection_wake(conn->raw_conn);
if (!!conn) {
sys_mutex_lock(&conn->activation_lock);
if (IS_ATOMIC_FLAG_SET(&conn->raw_opened)) {
pn_raw_connection_wake(conn->raw_conn);
}
sys_mutex_unlock(&conn->activation_lock);
}
break;
}
Expand Down

0 comments on commit bcbafec

Please sign in to comment.