Skip to content
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

examples: gcoap: stack overflow when NON times out #8981

Closed
miri64 opened this issue Apr 19, 2018 · 3 comments · Fixed by #8998
Closed

examples: gcoap: stack overflow when NON times out #8981

miri64 opened this issue Apr 19, 2018 · 3 comments · Fixed by #8998
Assignees
Labels
Area: network Area: Networking Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Comments

@miri64
Copy link
Member

miri64 commented Apr 19, 2018

Description

When I send a NON GET with the gcoap example the coap thread overflows if there is no request.

Steps to reproduce the issue

  1. Flash gcoap example to board (I used samr21-xpro, did not check for other types of boards)
  2. Check current stack usage:
> ps 
2018-04-19 11:26:19,614 - INFO #  ps
2018-04-19 11:26:19,622 - INFO # 	pid | name                 | state    Q | pri | stack  ( used) | base addr  | current     
2018-04-19 11:26:19,630 - INFO # 	  - | isr_stack            | -        - |   - |    512 (  148) | 0x20000000 | 0x200001b8
2018-04-19 11:26:19,638 - INFO # 	  1 | idle                 | pending  Q |  15 |    256 (  156) | 0x200006c0 | 0x20000724 
2018-04-19 11:26:19,646 - INFO # 	  2 | main                 | running  Q |   7 |   1536 ( 1040) | 0x200007c0 | 0x20000c04 
2018-04-19 11:26:19,655 - INFO # 	  3 | 6lo                  | bl rx    _ |   3 |   1024 (  460) | 0x200036a0 | 0x2000396c 
2018-04-19 11:26:19,663 - INFO # 	  4 | ipv6                 | bl rx    _ |   4 |   1024 (  432) | 0x20001764 | 0x20001a2c 
2018-04-19 11:26:19,671 - INFO # 	  5 | udp                  | bl rx    _ |   5 |   1024 (  272) | 0x20003e6c | 0x2000415c 
2018-04-19 11:26:19,680 - INFO # 	  6 | coap                 | bl mbox  _ |   6 |   1024 (  776) | 0x200012c4 | 0x200013bc 
2018-04-19 11:26:19,688 - INFO # 	  7 | at86rf2xx            | bl rx    _ |   2 |   1024 (  504) | 0x20000e84 | 0x20001174 
2018-04-19 11:26:19,694 - INFO # 	    | SUM                  |            |     |   7424 ( 3788)

Send CoAP NON to fake destination:

> coap get affe::1 5683 /test
2018-04-19 11:32:47,258 - INFO #  coap get affe::1 5683 /test
2018-04-19 11:32:47,262 - INFO # gcoap_cli: sending msg ID 22606, 11 bytes
> 2018-04-19 11:32:52,271 - INFO #  gcoap: timeout for msg ID 22606

Check stack usage again:

ps
2018-04-19 11:32:55,406 - INFO # ps
2018-04-19 11:32:55,414 - INFO # 	pid | name                 | state    Q | pri | stack  ( used) | base addr  | current     
2018-04-19 11:32:55,422 - INFO # 	  - | isr_stack            | -        - |   - |    512 (  164) | 0x20000000 | 0x200001b8
2018-04-19 11:32:55,430 - INFO # 	  1 | idle                 | pending  Q |  15 |    256 (  156) | 0x200006c0 | 0x20000724 
2018-04-19 11:32:55,439 - INFO # 	  2 | main                 | running  Q |   7 |   1536 ( 1052) | 0x200007c0 | 0x20000c04 
2018-04-19 11:32:55,447 - INFO # 	  3 | 6lo                  | bl rx    _ |   3 |   1024 (  460) | 0x200036a0 | 0x2000396c 
2018-04-19 11:32:55,455 - INFO # 	  4 | ipv6                 | bl rx    _ |   4 |   1024 (  432) | 0x20001764 | 0x20001a2c 
2018-04-19 11:32:55,463 - INFO # 	  5 | udp                  | bl rx    _ |   5 |   1024 (  328) | 0x20003e6c | 0x2000415c 
2018-04-19 11:32:55,472 - INFO # 	  6 | coap                 | bl mbox  _ |   6 |   1024 ( 1024) | 0x200012c4 | 0x200013bc 
2018-04-19 11:32:55,480 - INFO # 	  7 | �D                   | bl rx    _ |   2 |    279 ( -241) | 0x20000e84 | 0x20001174 
2018-04-19 11:32:55,486 - INFO # 	    | SUM                  |            |     |   6679 ( 3375)

Expected results

Stack should not overflow.

Actual results

Stack overflows and overwrites TCB of following thread (might cause crash later on).

Versions

This was done on 689333f of RIOT.

@miri64 miri64 added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: network Area: Networking labels Apr 19, 2018
@miri64 miri64 added this to the Release 2018.04 milestone Apr 19, 2018
@miri64
Copy link
Member Author

miri64 commented Apr 19, 2018

(I'm not sure if raising the stack size is the go-to solution here though it is obviously the simplest fix. Rather we should investigate why gcoap is using so much stack space in the first place (776 without even sending anything? Not even IPv6 and 6Lo which are quite complex as well are this wasteful).

@kb2ma
Copy link
Member

kb2ma commented Apr 19, 2018

Thanks for the report @miri64. I have not seen this issue. I am short on time at the moment, but I expect the added size in coap_pkt_t from #8772 has triggered this issue. Note this extra size is specific to gcoap, which still uses the old mechanism for storing options. I am working on adapting gcoap as described in #8831.

@kb2ma
Copy link
Member

kb2ma commented Apr 23, 2018

I confirmed that the stack issue surfaced with #8772. Prior to this PR, stack size was 724 initially, and 996 (out of 1024 available) after sending a message.

I did test gcoap when I reviewed #8772. I can only guess that I tested mostly on native.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: network Area: Networking Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants