Detected message duplications stop mbed-client #511
Description
Description
- Type: Bug
- Priority: Major
I enabled duplication detection by setting SN_COAP_DUPLICATION_MAX_MSGS_COUNT
to 4
. If a duplication is detected in the function sn_coap_protocol_parse
of sn_coap_protocol.c
. sn_coap_protocol_linked_list_duplication_info_search
returns a coap_duplication_info_s* response
where response->packet_ptr
is NULL
and response->packet_len
is zero. response->coap->sn_coap_tx_callback
is called then with those values as parameter and finaly M2MConnectionHandlerPimpl::send_data
returns false
because of the NULL
/zero values. The result is that M2MInterfaceImpl::coap_message_ready
emits a M2MInterface::NetworkError
(is this the expected behaviour?). This is no problem so far but it seems that if those errors are emitted often the lwm2m stack somehow just stops. I could not yet investigate why. If the code is altered not to propagate those NULL
-responses to sn_coap_tx_callback
everything seems to work fine.
Related code sections:
sn_coap_protocol_parse of file sn_coap_protocol.c:
#if SN_COAP_DUPLICATION_MAX_MSGS_COUNT/* If Message duplication is used, this part of code will not be compiled */
/* * * * Manage received CoAP message duplicate detection * * * */
/* If no message duplication detected */
if ((returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_CONFIRMABLE ||
returned_dst_coap_msg_ptr->msg_type == COAP_MSG_TYPE_NON_CONFIRMABLE) &&
handle->sn_coap_duplication_buffer_size != 0) {
if (sn_coap_protocol_linked_list_duplication_info_search(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id) == NULL) {
/* * * No Message duplication: Store received message for detecting later duplication * * */
/* Get count of stored duplication messages */
uint16_t stored_duplication_msgs_count = handle->count_duplication_msgs;
/* Check if there is no room to store message for duplication detection purposes */
if (stored_duplication_msgs_count >= handle->sn_coap_duplication_buffer_size) {
/* Get oldest stored duplication message */
coap_duplication_info_s *stored_duplication_info_ptr = ns_list_get_first(&handle->linked_list_duplication_msgs);
/* Remove oldest stored duplication message for getting room for new duplication message */
sn_coap_protocol_linked_list_duplication_info_remove(handle,
stored_duplication_info_ptr->address->addr_ptr,
stored_duplication_info_ptr->address->port,
stored_duplication_info_ptr->msg_id);
}
/* Store Duplication info to Linked list */
sn_coap_protocol_linked_list_duplication_info_store(handle, src_addr_ptr, returned_dst_coap_msg_ptr->msg_id, param);
} else { /* * * Message duplication detected * * */
/* Set returned status to User */
returned_dst_coap_msg_ptr->coap_status = COAP_STATUS_PARSER_DUPLICATED_MSG;
coap_duplication_info_s* response = sn_coap_protocol_linked_list_duplication_info_search(handle,
src_addr_ptr,
returned_dst_coap_msg_ptr->msg_id);
/* Send ACK response */
if (response) {
response->coap->sn_coap_tx_callback(response->packet_ptr,
response->packet_len, response->address, response->param);
}
return returned_dst_coap_msg_ptr;
}
}
#endif
M2MConnectionHandlerPimpl::send_data of file m2mconnectionhandlerimpl.cpp:
bool M2MConnectionHandlerPimpl::send_data(uint8_t *data,
uint16_t data_len,
sn_nsdl_addr_s *address)
{
arm_event_s event;
tr_debug("send_data()");
if (address == NULL || data == NULL || !data_len || !_running) {
tr_warn("send_data() too early");
return false;
}
//...
M2MInterfaceImpl::coap_message_ready of file m2minterfaceimpl.cpp:
void M2MInterfaceImpl::coap_message_ready(uint8_t *data_ptr,
uint16_t data_len,
sn_nsdl_addr_s *address_ptr)
{
tr_debug("M2MInterfaceImpl::coap_message_ready");
if (_current_state != STATE_IDLE) {
internal_event(STATE_SENDING_COAP_DATA);
if(!_connection_handler.send_data(data_ptr,data_len,address_ptr)) {
internal_event( STATE_IDLE);
tr_error("M2MInterfaceImpl::coap_message_ready() - M2MInterface::NetworkError");
if (!_reconnecting) {
_observer.error(M2MInterface::NetworkError);
}
}
}
}
Version Info:
Project (None)
|- mbed-client (31e5ce2)
| |- mbed-client-c (ecfa619e42b2)
| |- mbed-client-classic (4e66929607c3)
| - mbed-client-mbed-tls (7e1b6d815038) |- mbed-os (8828635da469)
- pal (60ce64d5ec35)