netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Thu Sep 06, 2018 9:38 pm

As title. I have a task that calls a function that does:

Code: Select all

netconn_write(conn, data, length, NETCONN_COPY);
Whether I send data fast or slow (so the 128KB can be over a second or a minute), in small packets or large, after sending 128KB without anything but acknowledgements from the receiving IP address, netconn_write no longer returns.

Wireshark trace shows no problems until that point, transmission just stops.

I always check that conn is not NULL before doing netconn_write.

If can receive and send megabytes of data when there is bidirectional traffic with complete stability, this seems to be a problem when transmitting only, which is a new part of my use case that I am surprised to discover so far into my project.

I'll need to work out more details and a minimal example if the above doesn't give any generic ideas or hints on what to try to watch. I've got a WROVER kit but so far not got into JTAG debugging on it, but I will end up hanging in unfamilar lwip code.

I was not aware of having to manually flush anything when doing netconn_write. I don't think I'm doing anything silly with the heap, the buffers I'm sending here are actually static and reused.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Thu Sep 06, 2018 9:52 pm

Noticed the heap is disappearing. To test, 10ms is printed every time a group of 8 messages is received from the CAN bus, which are being sent every 10ms by another module on the CAN bus. Before I opened a TCP connection, (so netconn_write was never called), the heap was sitting at heap_free_size 193392. A drop of 5KB on opening a connection is expected and initially it is stable. Then ~80% of the way in it loses about half the heap quickly and netconn_write doesn't return. There is no dependency elsewhere in the application that does anything with the heap in any way I can think of that is related, but I could be wrong and will investigate further.

Code: Select all

10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 188480
10ms, heap_free_size 186848
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 185124
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 183432
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 185128
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 186964
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 185120
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 183432
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 186680
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 186620
10ms, heap_free_size 186680
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188304
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 183432
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 186980
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 186564
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188308
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 185128
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188312
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 186620
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 188316
10ms, heap_free_size 186752
10ms, heap_free_size 186752
10ms, heap_free_size 186752
10ms, heap_free_size 186752
10ms, heap_free_size 186752
10ms, heap_free_size 185188
10ms, heap_free_size 185188
10ms, heap_free_size 185188
10ms, heap_free_size 185188
10ms, heap_free_size 185188
10ms, heap_free_size 183612
10ms, heap_free_size 183624
10ms, heap_free_size 183624
10ms, heap_free_size 183624
10ms, heap_free_size 183624
10ms, heap_free_size 182060
10ms, heap_free_size 182060
10ms, heap_free_size 182060
10ms, heap_free_size 182060
10ms, heap_free_size 182060
10ms, heap_free_size 180496
10ms, heap_free_size 180496
10ms, heap_free_size 180496
10ms, heap_free_size 180496
10ms, heap_free_size 180496
10ms, heap_free_size 178932
10ms, heap_free_size 178932
10ms, heap_free_size 178932
10ms, heap_free_size 178932
10ms, heap_free_size 178932
10ms, heap_free_size 177368
10ms, heap_free_size 177368
10ms, heap_free_size 177368
10ms, heap_free_size 177368
10ms, heap_free_size 177368
10ms, heap_free_size 175804
10ms, heap_free_size 175804
10ms, heap_free_size 175804
10ms, heap_free_size 175804
10ms, heap_free_size 175804
10ms, heap_free_size 174240
10ms, heap_free_size 174240
10ms, heap_free_size 174240
10ms, heap_free_size 174240
10ms, heap_free_size 174240
10ms, heap_free_size 172676
10ms, heap_free_size 172676
10ms, heap_free_size 172676
10ms, heap_free_size 172676
10ms, heap_free_size 172676
10ms, heap_free_size 171112
10ms, heap_free_size 171112
10ms, heap_free_size 171112
10ms, heap_free_size 171112
10ms, heap_free_size 171112
10ms, heap_free_size 169548
10ms, heap_free_size 169548
10ms, heap_free_size 169548
10ms, heap_free_size 169548
10ms, heap_free_size 169548
10ms, heap_free_size 167984
10ms, heap_free_size 167984
10ms, heap_free_size 167984
10ms, heap_free_size 167984
10ms, heap_free_size 167984
10ms, heap_free_size 166420
10ms, heap_free_size 166420
10ms, heap_free_size 166420
10ms, heap_free_size 166420
10ms, heap_free_size 166420
10ms, heap_free_size 164856
10ms, heap_free_size 164856
10ms, heap_free_size 164856
10ms, heap_free_size 164856
10ms, heap_free_size 164856
10ms, heap_free_size 163292
10ms, heap_free_size 163292
10ms, heap_free_size 163292
10ms, heap_free_size 163292
10ms, heap_free_size 163292
10ms, heap_free_size 161728
10ms, heap_free_size 161728
10ms, heap_free_size 161728
10ms, heap_free_size 161728
10ms, heap_free_size 161728
10ms, heap_free_size 160164
10ms, heap_free_size 160164
10ms, heap_free_size 160164
10ms, heap_free_size 160164
10ms, heap_free_size 160164
10ms, heap_free_size 158600
10ms, heap_free_size 158600
10ms, heap_free_size 158600
10ms, heap_free_size 158600
10ms, heap_free_size 158600
10ms, heap_free_size 157036
10ms, heap_free_size 157036
10ms, heap_free_size 157036
10ms, heap_free_size 157036
10ms, heap_free_size 157036
10ms, heap_free_size 155472
10ms, heap_free_size 155472
10ms, heap_free_size 155472
10ms, heap_free_size 155472
10ms, heap_free_size 155472
10ms, heap_free_size 153908
10ms, heap_free_size 153908
10ms, heap_free_size 153908
10ms, heap_free_size 153908
10ms, heap_free_size 153908
10ms, heap_free_size 152344
10ms, heap_free_size 152344
10ms, heap_free_size 152344
10ms, heap_free_size 152344
10ms, heap_free_size 152344
10ms, heap_free_size 150780
10ms, heap_free_size 150780
10ms, heap_free_size 150780
10ms, heap_free_size 150780
10ms, heap_free_size 150780
10ms, heap_free_size 149216
10ms, heap_free_size 149216
10ms, heap_free_size 149216
10ms, heap_free_size 149216
10ms, heap_free_size 149216
10ms, heap_free_size 147652
10ms, heap_free_size 147652
10ms, heap_free_size 147652
10ms, heap_free_size 147652
10ms, heap_free_size 147652
10ms, heap_free_size 146088
10ms, heap_free_size 146088
10ms, heap_free_size 146088
10ms, heap_free_size 146088
10ms, heap_free_size 146088
10ms, heap_free_size 144524
10ms, heap_free_size 144524
10ms, heap_free_size 144524
10ms, heap_free_size 144524
10ms, heap_free_size 144524
10ms, heap_free_size 142960
10ms, heap_free_size 142960
10ms, heap_free_size 142960
10ms, heap_free_size 142960
10ms, heap_free_size 142960
10ms, heap_free_size 141396
10ms, heap_free_size 141396
10ms, heap_free_size 141396
10ms, heap_free_size 141396
10ms, heap_free_size 141396
10ms, heap_free_size 139832
10ms, heap_free_size 139832
10ms, heap_free_size 139832
10ms, heap_free_size 139832
10ms, heap_free_size 139832
10ms, heap_free_size 138268
10ms, heap_free_size 138268
10ms, heap_free_size 138268
10ms, heap_free_size 138268
10ms, heap_free_size 138268
10ms, heap_free_size 136704
10ms, heap_free_size 136704
10ms, heap_free_size 136704
10ms, heap_free_size 136704
10ms, heap_free_size 136704
10ms, heap_free_size 135140
10ms, heap_free_size 135140
10ms, heap_free_size 135140
10ms, heap_free_size 135140
10ms, heap_free_size 135140
10ms, heap_free_size 133576
10ms, heap_free_size 133576
10ms, heap_free_size 133576
10ms, heap_free_size 133576
10ms, heap_free_size 133576
10ms, heap_free_size 132012
10ms, heap_free_size 132012
10ms, heap_free_size 132012
10ms, heap_free_size 132012
10ms, heap_free_size 132012
10ms, heap_free_size 130448
10ms, heap_free_size 130448
10ms, heap_free_size 130448
10ms, heap_free_size 130448
10ms, heap_free_size 130448
10ms, heap_free_size 128884
10ms, heap_free_size 128884
10ms, heap_free_size 128884
10ms, heap_free_size 128884
10ms, heap_free_size 128884
10ms, heap_free_size 127320
10ms, heap_free_size 127320
10ms, heap_free_size 127320
10ms, heap_free_size 127320
10ms, heap_free_size 127320
10ms, heap_free_size 125760
10ms, heap_free_size 125760
10ms, heap_free_size 125760
10ms, heap_free_size 125760
10ms, heap_free_size 125760
10ms, heap_free_size 124196
10ms, heap_free_size 124196
10ms, heap_free_size 124196
10ms, heap_free_size 124196
10ms, heap_free_size 124196
10ms, heap_free_size 122632
10ms, heap_free_size 122632
10ms, heap_free_size 122632
10ms, heap_free_size 122632
10ms, heap_free_size 122632
10ms, heap_free_size 121068
10ms, heap_free_size 121068
10ms, heap_free_size 121068
10ms, heap_free_size 121068
10ms, heap_free_size 121068
10ms, heap_free_size 119504
10ms, heap_free_size 119504
10ms, heap_free_size 119504

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Thu Sep 06, 2018 10:39 pm

Reducing the TCP Tx and Rx buffers from 64KB to 16KB changes it so that the heap size only reduces by this amount, but it hangs after the same amount of data has been transferred. Increased TCP stack size to 5120 bytes and disabled LWIP IRAM optimization, no difference. Disabling Nagle's algorithm makes no difference (the payloads are 284 bytes, in single segments without Nagle, with Nagle, because it is unidirectional with 40ms delayed ACK from Windows, typically four of the 284 byte messages that were arriving every 10ms were being combined). Increasing the priority of the calling task makes no difference, idle times are 45 and 49% on each core anyway.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Thu Sep 06, 2018 11:27 pm

It might be that I need to understand TCP windows better. The TCP packets are being ack'd but I am not sending anything back at the application level to all this data coming from the ESP32. Does a TCP stream need anything more than ACKs at the driver level to continue? The heap gets used up after the last packet has been sent I noticed. Heap corruption detection also on comprehensive.

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby ESP_Angus » Fri Sep 07, 2018 3:55 am

Is all the data being received by the other end correctly? If not, it may be as simple as the TCP window is ballooning up with un-ACKed data.

You can try using heap tracing in leak checker mode to see where the leaked allocations are being made:
https://docs.espressif.com/projects/esp ... mory-leaks

It's possible there's a leak in the netconn API under some conditions, we tend to recommend (and test) the BSD sockets API instead (although sockets API is built on top of netconn, so in general it can be expected to work).

Any chance you can provide a simple test case that demonstrates the problem?

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Fri Sep 07, 2018 9:28 am

Thanks, will try to make a minimal example and probably learn some things doing so. I have a temporary fix in that the transmissions continue with no heap degradation whilst I send some TCP packets also in the other direction. My suspicion is that something is accumulating inside lwip during continuous transmission that is freed by receiving a TCP packet, but it could be my application so we'll see.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Fri Sep 07, 2018 11:47 am

Happens with minimal example too but for getting something others can test I tried PuTTY on Windows to open the TCP connection and it has no problem but isn't sending data back. So now trying to make minimal C# and C++ examples to test.

Your first suggestion may be correct ESP_Angus, but I'll need to look closer than just looking for a pattern of ACKs in Wireshark.

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Fri Sep 07, 2018 12:24 pm

Minimal C# example does have the problem:

Code: Select all

            TcpClient client = new TcpClient();
            client.Connect("192.168.1.172", 9998);
With this example, the TCP window that the Windows PC sends back in its ACKs dwindles from 64KB to almost nothing before lwip blocks on netconn_write.

When I connect with PuTTY, the TCP window that the Windows PC sends back in its ACKs stays near 64KB and megabytes are transferred.

Clearly then it is a problem in my Windows apps in that I need to do something with the data at application level rather than test like this, and not a problem with lwip. Thanks for the help! Edit: turns out that I need to consume the data from the socket in Windows. Sounds obvious in hindsight, thought a quick and dirty test of throwing data at a connection would work.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby fly135 » Fri Sep 07, 2018 6:53 pm

I use the BSD sockets API and send 240K uploads of sound data with no real issues except for maybe in a crowded wifi environment.

John A

jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: netconn_write hangs after transmitting 128KB (fine with megabytes bidirectional)

Postby jcsbanks » Fri Sep 07, 2018 8:11 pm

Thanks John, working great now I am reading the socket on the Windows side.

Who is online

Users browsing this forum: Baidu [Spider] and 78 guests