libcoap icon indicating copy to clipboard operation
libcoap copied to clipboard

" large body receive internal issue " error when receiving observed resource via block-wise transfer

Open sixdenip opened this issue 5 years ago • 9 comments

Problem

I'm trying to send data using block-wise transfer and Observable resources. I managed to send large data before but now I'm getting the message large body receive internal issue and I don't know what it means... On the client side, only the first packet is transmitted (with the block-specific options, which it's not supposed to). Of course I set coap_context_set_block_mode(ctx, COAP_BLOCK_USE_LIBCOAP | COAP_BLOCK_SINGLE_BODY); coap_register_option(ctx, COAP_OPTION_BLOCK2); at the beginning of my code. I tried to remove the custom options that I added and the same thing happened.

Server-side:

v:1 t:CON c:2.05 i:9c31 {} [ Observe:54, Content-Format:application/octet-stream, 2048:\x77\x61\x76\x65\x66\x6F\x72\x6D\x5F\x31\x37\x37\x32\x2E\x72\x61\x77, 2050:\x73\x61\x6D\x70\x6C\x65 ] :: binary data length 21200940
<<binary data>>

Oct 05 18:11:37.686 INFO Response sentOct 05 18:11:37.686 DEBG *  [::]:5680 <-> [::1]:60383 UDP : sent 1070 bytes
v:1 t:CON c:2.05 i:9c31 {} [ ETag:0x37, Observe:54, Content-Format:application/octet-stream, Block2:0/M/1024, Size2:21200940, 2048:\x77\x61\x76\x65\x66\x6F\x72\x6D\x5F\x31\x37\x37\x32\x2E\x72\x61\x77, 2050:\x73\x61\x6D\x70\x6C\x65 ] :: binary data length 1024
<<binary data>>

Client-side:

v:1 t:CON c:2.05 i:9c31 {} [ ETag:0x37, Observe:54, Content-Format:application/octet-stream, Block2:0/M/1024, Size2:21200940, 2048:\x77\x61\x76\x65\x66\x6F\x72\x6D\x5F\x31\x37\x37\x32\x2E\x72\x61\x77, 2050:\x73\x61\x6D\x70\x6C\x65 ] :: binary data length 1024
<<binary data>>

Oct 05 18:11:38.238 DEBG ** [::1]:60383 <-> [::1]:5680 UDP : large body receive internal issue
v:1 t:CON c:2.05 i:9c31 {} [ ETag:0x37, Observe:54, Content-Format:application/octet-stream, Block2:0/M/1024, Size2:21200940, 2048:\x77\x61\x76\x65\x66\x6F\x72\x6D\x5F\x31\x37\x37\x32\x2E\x72\x61\x77, 2050:\x73\x61\x6D\x70\x6C\x65 ] :: binary data length 1024
<<binary data>>

Thanks for your help.

sixdenip avatar Oct 05 '21 16:10 sixdenip

coap_register_option(ctx, COAP_OPTION_BLOCK2); is not required as the option is already known about.

The first record that you report on the client side is a response, not a request. Hence why you are seeing the Block2 option.

What is the actual request (or are you just expecting an unsolicited response)?

As the log entries provided all have i:9c31, it is my suspicion that these are retried/retransmitted responses as each new request / response should have its own unique message id.

Are you doing the Observe set up request when also sending data in the same packet - if so, you should be using FETCH Instead of GET.

large body receive internal issue is reported when the lg_crcv structure has not been set up, or has prematurely been freed off and there is an unexpected unsolicited response.

Your issue may be that you are not using Tokens that are unique per request so that responses can be correctly matched by the originating request - see Token and coap_session_new_token(3)

mrdeep1 avatar Oct 05 '21 17:10 mrdeep1

Thanks for you fast response. This is the request : v:1 t:CON c:GET i:9c31 {} [ Observe:0, Uri-Path:sample, Uri-Path:waveform ] But in my app it supposed to be the only one, as every response should be unexpected updates from the server. I am, I'll look into FETCH. I've tried a quick fix by adding a token, now the blocks are transfering but it stops after 13 blocks, I have to investigate more. But how am I supposed to use token with an observable resource ? Since I'm supposed to set it in the request from the client but there's no request.

sixdenip avatar Oct 05 '21 17:10 sixdenip

As you do not have any data in your GET request, there is no need to use FETCH as an alternative.

As per 4.1 Request, everything is matched on the endpoint / token.

When a request is recieved by the server to Observe a resource, the response is the current state of the resource along with the Observe option to indicate that the Observe subscription was successful. The token used in this request is the same token that will be used in any response associated with this Observe.

A resource being Observed can send off an unsolicited response at any time (within reason - sending off many unsolicited responses at once is not recommended...).

I would look at what is reported with respect to lg_crcv information - this structure should remain throughout the lifetime of potentially recieving an unsolicited Observe response.

The large size of 21200940 (21M) should work fine (there is a limit of 1G) - the receiving logic should generate a block of memory with this size to receive the data into. I do not recognize your option that has a number value of 2048, but do not think that this is the issue.

What is in the logs around the failure circa the 13th recieved block?

mrdeep1 avatar Oct 05 '21 18:10 mrdeep1

Using the standard coap-client and coap-server, 21200940 transfers with no issue.

mrdeep1 avatar Oct 05 '21 18:10 mrdeep1

Just seen a potential issue - checking into it.

mrdeep1 avatar Oct 05 '21 18:10 mrdeep1

The issue occurs when the current response is still being processed (not all the blocks have yet been received) and a new Observe unsolicited response is sent starting from block number 0. The two responses are entwined with each other and then things get confused, giving the "large body receive internal issue" error.

I will look into how this best can be handled so the error does not occur.

In the mean time, do you need to send off the Observe updates so frequently?

mrdeep1 avatar Oct 05 '21 19:10 mrdeep1

The issue occurs when the current response is still being processed (not all the blocks have yet been received) and a new Observe unsolicited response is sent starting from block number 0. The two responses are entwined with each other and then things get confused, giving the "large body receive internal issue" error.

I will look into how this best can be handled so the error does not occur.

In the mean time, do you need to send off the Observe updates so frequently?

Actually I don't, I reduced the update rate and now the transfer has time to complete. I might run more tests to see if the error still happen over time.

Regarding the fix... Maybe something using the message id to differentiate the two block responses ?

Side question : any way to find out there's a block transfer currently happening ? Currently I just check the current value of coap_io_process()

sixdenip avatar Oct 05 '21 21:10 sixdenip

Good that increasing the time between triggering the unsolicited responses is a good workaround.

Side question : any way to find out there's a block transfer currently happening ? Currently I just check the current value of coap_io_process()

Not from the application layer. I need to do this type of check in a lower layer (not start a new transmission until the previous one has finished), but cover the case when a client has elected not to recieve all of the body of data that spans multiple payloads.

The delaying/dropping of the next unsolicited response is already handled in the case of the body of data fitting into a single packet and the previous response transmission using CON has not yet been ACK'd by the client (likely down to a lossy network).

mrdeep1 avatar Oct 06 '21 10:10 mrdeep1

See the fix in PR #759.

mrdeep1 avatar Oct 06 '21 14:10 mrdeep1