Skip to content

Commit

Permalink
Merge pull request #803 from ZettaScaleLabs/liveliness_cleanup_fix
Browse files Browse the repository at this point in the history
Fix liveliness cleanup
  • Loading branch information
milyin authored Nov 21, 2024
2 parents 6ef391e + 4983d0f commit 6691afc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/zenoh-pico/api/liveliness.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct {
_z_session_weak_t _zn;
} _z_liveliness_token_t;

_z_liveliness_token_t _z_liveliness_token_null(void);
_Z_OWNED_TYPE_VALUE(_z_liveliness_token_t, liveliness_token)
_Z_OWNED_FUNCTIONS_DEF(liveliness_token)

Expand Down
18 changes: 13 additions & 5 deletions src/api/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ _z_liveliness_token_t _z_liveliness_token_null(void) {
}

void _z_liveliness_token_clear(_z_liveliness_token_t *token) {
_z_session_rc_t sess_rc = _z_session_weak_upgrade_if_open(&token->_zn);
if (!_Z_RC_IS_NULL(&sess_rc)) {
_z_undeclare_liveliness_token(token);
_z_session_rc_drop(&sess_rc);
if (!_z_liveliness_token_check(token)) {
return;
}
// TODO(sashacmc): implement proper check
if (token->_zn._val != NULL) {
_z_session_rc_t sess_rc = _z_session_weak_upgrade_if_open(&token->_zn);
if (!_Z_RC_IS_NULL(&sess_rc)) {
_z_undeclare_liveliness_token(token);
_z_session_rc_drop(&sess_rc);
}
_z_session_weak_drop(&token->_zn);
}
_z_keyexpr_clear(&token->_key);
}
Expand Down Expand Up @@ -132,7 +139,8 @@ z_result_t z_liveliness_get(const z_loaned_session_t *zs, const z_loaned_keyexpr
opt = *options;
}

ret = _z_liveliness_query(_Z_RC_IN_VAL(zs), *keyexpr, callback->_this._val.call, callback->_this._val.drop, ctx,
_z_keyexpr_t ke = _z_keyexpr_duplicate(*keyexpr);
ret = _z_liveliness_query(_Z_RC_IN_VAL(zs), ke, callback->_this._val.call, callback->_this._val.drop, ctx,
opt.timeout_ms);

z_internal_closure_reply_null(
Expand Down
2 changes: 2 additions & 0 deletions src/net/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ z_result_t _z_undeclare_liveliness_token(_z_liveliness_token_t *token) {
ret = _z_send_n_msg(_Z_RC_IN_VAL(&token->_zn), &n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK);
_z_n_msg_clear(&n_msg);

*token = _z_liveliness_token_null();
return ret;
}

Expand Down Expand Up @@ -163,6 +164,7 @@ z_result_t _z_liveliness_query(_z_session_t *zn, _z_keyexpr_t keyexpr, _z_closur

} else {
_z_liveliness_pending_query_clear(pq);
z_free(pq);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/session/liveliness.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ z_result_t _z_liveliness_register_pending_query(_z_session_t *zn, uint32_t id, _
_Z_ERROR("Duplicate liveliness query id %i", (int)id);
ret = _Z_ERR_ENTITY_DECLARATION_FAILED;
} else {
_z_liveliness_pending_query_intmap_insert(&zn->_liveliness_pending_queries, id,
_z_liveliness_pending_query_clone(pen_qry));
_z_liveliness_pending_query_intmap_insert(&zn->_liveliness_pending_queries, id, pen_qry);
}

_zp_session_unlock_mutex(zn);
Expand Down
1 change: 1 addition & 0 deletions tests/z_api_liveliness_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ void test_liveliness_get(void) {
assert(z_fifo_handler_reply_recv(z_fifo_handler_reply_loan(&handler), &reply) == Z_CHANNEL_DISCONNECTED);

z_fifo_handler_reply_drop(z_fifo_handler_reply_move(&handler));
z_closure_reply_drop(z_closure_reply_move(&cb));

assert_ok(zp_stop_read_task(z_loan_mut(s1)));
assert_ok(zp_stop_read_task(z_loan_mut(s2)));
Expand Down

0 comments on commit 6691afc

Please sign in to comment.