-
Notifications
You must be signed in to change notification settings - Fork 423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiblock GET request with Etag incorrectly invokes handler twice for COAP_BLOCK_SINGLE_BODY #1541
Comments
Thanks for raising this. I am able to reproduce the issue and will look at creating a fix. The example server code does not track responses and Etags so does not generate a 2.03 response. However, adding in code in the server application handler such as you have done will cause 2.03 responses to be generated when appropriate as you are tracking the Etag in pstResource. |
@cdurkin Please checkout out #1545 which I believe fixes your issue.
#1545 now does this in the libcoap library. However, for the server, if |
Thanks very much, i'll give this a test hopefully early this coming week and report back. Assuming no further issues, when do you think you'll do the next release that will include this fix, as I'd rather update our product to a tagged release of libcoap then just this commit. |
There are no immediate plans for the next tagged release of libcoap. I certainly would like to give this fix some airtime before doing a tag (it has had lots of testing, but .....). If you cherry pick this fix on top of 4.3.5, you will also need to include #1543. |
Apologies only just got to testing this but all looks good, thanks very much :) |
Thanks for the confirmation. I will close this now. |
Environment
libcoap Configuration Summary
libcoap package version : "4.3.5"
libcoap package source : "4.3.5"
libcoap API version : "3"
libcoap ABI version : "3.2.0"
libcoap libtool SO version : "5.0.2"
libcoap DTLS lib extn : "-mbedtls"
host system : "x86_64-pc-linux-gnu"
build with server support : "yes"
build with client support : "yes"
build with proxy support : "yes"
build with IPv4 support : "yes"
build with IPv6 support : "yes"
build with Unix socket support : "yes"
build with TCP support : "yes"
build DTLS support : "yes"
--> Mbed TLS around : "yes" (found Mbed TLS without pkg-config)
MbedTLS_CFLAGS : ""
MbedTLS_LIBS : ""
build DTLS support : "no"
add default names : "yes"
build Observe Persist : "yes"
build using epoll : "yes"
enable small stack size : "no"
enable separate responses : "yes"
enable OSCORE support : "yes"
enable Q-Block support : "yes"
enable max logging level : "none"
enable thread safe code : "yes"
enable recursive lock check : "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 : "yes"
build static library : "yes"
Problem Description
Performing a GET for a large resource (i.e. one that triggers a multiblock response) that includes an Etag causes the GET handler to be invoked twice causing the 2nd block in the response to be missing the Etag.
The logs include warnings: "dbg: ***EVENT: COAP_EVENT_XMIT_BLOCK_FAIL" and "Warn: Not all blocks have ETag option"
Expected Behavior
My test to pass, my GET_Handler to only be invoked once regardless of whether the GET request in includes an Etag or not.
Code to reproduce this issue
I'm working on a embedded device using FreeRTOS where we have one task for the CoAP client and one for the CoAP server. The server sets block mode i.e.
When we create resource we set them as observerable (doubt this matters but it just in case) and set GET and PUT handlers i.e.
My GET handler
Debug Logs
Other info
So I've investigated and traced this down to line 2479 of coap_block.c,
The fact the request has an etag is triggering this if() and because the etags don't match the code hits line 2484 causing the GET handler to be called gain despite the fact we don't want it to because block mode is COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY and surely because the etags don't match hence we do want to include the payload in the response?
I've worked around this issue by simply commented out line 2478 so etag_opt remains NULL and the if() is not triggered but obviously this is not a correct fix.
This code looks like it should be doing the appropriate check if the etags match and setting response code 2.03 but this code only invokes during block transfer. As shown above I've added code in my GET Handler to check if the etags match and return 2.03 (i.e. so this handles all cases regardless of whether the response is multiblock or not).
Please let me know if libcoap handles the checking of etags and responding with 2.03 but i didn't notice this in the documentation.
Thanks
Chris
The text was updated successfully, but these errors were encountered: