obgm / libcoap

A CoAP (RFC 7252) implementation in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RST sent to error code piggy backed response "got RST for mid"

AnyFlyGuy opened this issue · comments

Environment

  • Build System: CMake
  • Operating System: Linux
  • Operating System Version: 22.04
  • Hosted Environment: None

libcoap Configuration Summary

libcoap package version  : "4.3.1"
libcoap library version  : "3.0.0"
libcoap API version      : "3"
libcoap DTLS lib extn    : "-notls"
host system              : "x86_64-pc-linux-gnu"
  build with server support: "yes"
  build with client support: "yes"
  build with TCP support   : "yes"
  build DTLS support       : "no"
  add default names        : "yes"
  build using epoll        : "yes"
  enable small stack size  : "no"
  enable separate responses: "yes"
  build doxygen pages      : "no"
  build man pages          : "no"
  build unit test binary   : "no"
  build examples           : "yes"
  install examples source  : "yes"
  build with gcov support  : "no"
  build shared library     : "no"
  build static library     : "yes"

Problem Description

If the server responds with any 4.xx or 5.xx error code to a PUT or POST from the client, the client sends an RST back to the server resulting in a log message ALRT got RST for mid=0xHHHH.

Please clarify if this is intended behavior, user error or a deviation from the RFC (in which I could not find anything describing this specific behavior).

The observed sequence is (same message ID for all):

Client -> Server : CON, POST
Server -> Client : ACK, 5.00 Internal Server Error
Client -> Server : RST

(Wireshark screenshot shows small integration test, with a server sending positive or negative status codes, while the Piggybacked response is the same.)

image

Expected Behavior

No RST after Piggybacked response with negative status codes.

Actual Behavior

RST after Piggybacked response with negative status codes.

Steps to reproduce

Server responds with any 4.xx or 5.xx error code to a PUT or POST.

Code to reproduce this issue

Server handler snippet (to stress this is part of our unit testing framework, where the server deliberately sends an error code every other request)

coap_add_data_large_response(resource,
                               session,
                               incoming_pdu,
                               response_pdu,
                               query,
                               COAP_MEDIATYPE_TEXT_PLAIN,
                               -1,
                               0,
                               response.length(),
                               reinterpret_cast<const uint8_t*>(response.c_str()),
                               nullptr,
                               nullptr);
  if (error_counter % 2 == 0) {
    coap_pdu_set_code(response_pdu, COAP_RESPONSE_CODE_CREATED);
  } else if (error_counter % 2 == 1) {
    coap_pdu_set_code(response_pdu, COAP_RESPONSE_CODE_INTERNAL_ERROR);
  }
  error_counter++;

I believe this is fixed in #1265 which is in the current develop branch. Please confirm that #1265 fixes your issue.

A RST should not be generated unless the incoming packet type is CON or NON.

Hi,
thank you for your support, I can confirm from the Wireshark and CoAP debug log, that the issue is resolved on the develop branch.

Can this be closed now?

Yes please.