Skip to content

Commit

Permalink
Reuse task attributes, break reopen on critial errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Dec 13, 2024
1 parent c9d0b2c commit 579c630
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions include/zenoh-pico/net/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ extern "C" {
typedef struct _z_session_t {
#if Z_FEATURE_MULTI_THREAD == 1
_z_mutex_t _mutex_inner;
z_task_attr_t *_lease_task_attr;
z_task_attr_t *_read_task_attr;
#endif // Z_FEATURE_MULTI_THREAD == 1

// Zenoh-pico is considering a single transport per session.
Expand Down
24 changes: 15 additions & 9 deletions src/net/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,25 +174,27 @@ z_result_t _z_reopen(_z_session_rc_t *zn) {

do {
ret = _z_open(zn, &zs->_config, &zs->_local_zid);
// TODO(sashacmc): break on fatal error, and add timeout config
if (ret != _Z_RES_OK) {
_Z_DEBUG("Reopen failed: %i, next try in 1s", ret);
z_sleep_s(1);
continue;
if (ret == _Z_ERR_TRANSPORT_OPEN_FAILED || ret == _Z_ERR_SCOUT_NO_RESULTS) {
_Z_DEBUG("Reopen failed, next try in 1s");
z_sleep_s(1);
continue;
} else {
_Z_ERROR("Reopen failed: %i", ret);
return ret;
}
}

#if Z_FEATURE_MULTI_THREAD == 1
// TODO (sashacmc): currnetly we can come to reopen only from task, so we can restart them
// but we have no original attributes (which currently for most cases is default)
_zp_start_lease_task(_Z_RC_IN_VAL(zn), NULL);
_zp_start_read_task(_Z_RC_IN_VAL(zn), NULL);
_zp_start_lease_task(zs, zs->_lease_task_attr);
_zp_start_read_task(zs, zs->_read_task_attr);
#endif // Z_FEATURE_MULTI_THREAD == 1

if (ret == _Z_RES_OK && !_z_network_message_list_is_empty(zs->_decalaration_cache)) {
_z_network_message_list_t *iter = zs->_decalaration_cache;
while (iter != NULL) {
_z_network_message_t *n_msg = _z_network_message_list_head(iter);
ret = _z_send_n_msg(_Z_RC_IN_VAL(zn), n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK);
ret = _z_send_n_msg(zs, n_msg, Z_RELIABILITY_RELIABLE, Z_CONGESTION_CONTROL_BLOCK);
if (ret != _Z_RES_OK) {
_Z_DEBUG("Send message during reopen failed: %i", ret);
continue;
Expand Down Expand Up @@ -326,6 +328,8 @@ z_result_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) {
// Free task if operation failed
if (ret != _Z_RES_OK) {
z_free(task);
} else {
zn->_read_task_attr = attr;
}
return ret;
}
Expand Down Expand Up @@ -355,6 +359,8 @@ z_result_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) {
// Free task if operation failed
if (ret != _Z_RES_OK) {
z_free(task);
} else {
zn->_lease_task_attr = attr;
}
return ret;
}
Expand Down
1 change: 0 additions & 1 deletion src/protocol/definitions/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void _z_t_msg_close_clear(_z_t_msg_close_t *msg) { (void)(msg); }
void _z_t_msg_keep_alive_clear(_z_t_msg_keep_alive_t *msg) { (void)(msg); }

void _z_t_msg_frame_clear(_z_t_msg_frame_t *msg) {
// TODO (sashacmc): make in more correct way
if (!msg->_messages._aliased) {
_z_network_message_svec_clear(&msg->_messages);
}
Expand Down
1 change: 0 additions & 1 deletion src/session/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ z_result_t _z_handle_network_message(_z_session_rc_t *zsrc, _z_zenoh_message_t *
}
}
}
// TODO (sashacmc): why it was removed???
_z_msg_clear(msg);
return ret;
}

0 comments on commit 579c630

Please sign in to comment.