-
Notifications
You must be signed in to change notification settings - Fork 3k
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
UDP echotests fix in case of no memory or device busy. #12333
Conversation
@@ -94,6 +94,9 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto) | |||
} else { | |||
sent = sock.send(tx_buffer, pkt_s); | |||
} | |||
if (sent == NSAPI_ERROR_NO_MEMORY) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to do the same for the non-blocking implementation?
And don't we need to check for NSAPI_ERROR_BUSY
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets re-think this..
Your sleep_for()
might be fixing the issue, but only because it adds some delay.
But within that delay, there might be other packets coming (duplicates), cumulating our input buffers.
So instead of adding a error handling here, we should follow a generic UDP application priciples:
- Ignore send errors.
- Don't retry immediately.
- Let upper layer or application logic handle the retries and timeouts.
Our application logic is a few lines down. On line 103 on original. There is continue
call, which immediately retries. So to fix this, I propose that we remove the continue
and allow it to flow directly into the receive()
loop that starts from line 106.
Notice that in case the packet did not really go out, we get nothing back, and this loop will restart. So the retry logic is there already. But instead of immediately retrying, it would allow recv()
or recvfrom()
to drain potential duplicate packets away from input buffers.
So, we should be OK with only one "sleep" within this logic. If this does not work, make sure that SOCKET_TIMEOUT
is long enough that we do sleep in recvfrom()
and while doing that, drain our input buffers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done as you suggested. Both continue and sleep removed.
It's also working fine.
@tymoteuszblochmobica, thank you for your changes. |
@@ -94,6 +94,9 @@ void UDPSOCKET_ECHOTEST_impl(bool use_sendto) | |||
} else { | |||
sent = sock.send(tx_buffer, pkt_s); | |||
} | |||
if (sent == NSAPI_ERROR_NO_MEMORY) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets re-think this..
Your sleep_for()
might be fixing the issue, but only because it adds some delay.
But within that delay, there might be other packets coming (duplicates), cumulating our input buffers.
So instead of adding a error handling here, we should follow a generic UDP application priciples:
- Ignore send errors.
- Don't retry immediately.
- Let upper layer or application logic handle the retries and timeouts.
Our application logic is a few lines down. On line 103 on original. There is continue
call, which immediately retries. So to fix this, I propose that we remove the continue
and allow it to flow directly into the receive()
loop that starts from line 106.
Notice that in case the packet did not really go out, we get nothing back, and this loop will restart. So the retry logic is there already. But instead of immediately retrying, it would allow recv()
or recvfrom()
to drain potential duplicate packets away from input buffers.
So, we should be OK with only one "sleep" within this logic. If this does not work, make sure that SOCKET_TIMEOUT
is long enough that we do sleep in recvfrom()
and while doing that, drain our input buffers.
This gives possibility of freeing memory and mesh device recover from busy state.
96a9dc0
to
a185d6c
Compare
Pull request has been modified.
Done as Seppo suggested. Both continue and sleep removed. |
CI started |
Test run: SUCCESSSummary: 5 of 5 test jobs passed |
This PR does not contain release version label after merging. |
Investigating why the label is being not picked up :/ |
UDP echotests hold in case of memory or device busy status.
This gives possibility of freeing memory and mesh device recover from busy state.
Summary of changes
If Wisun mesh is running and mbed-trace is disabled
UDP burst tests consumes all available memory and sendto fails with NSAPI_ERROR_NO_MEMORY because Nanostack ns_mem_internal_alloc returns NULL buffer.
Problem is with temporary memory lack this fix gives time to memory manager for freeing unused memory pools.
Impact of changes
No
Migration actions required
No
Documentation
Pull request type
Test results
Reviewers
@SeppoTakalo
@AnttiKauppila
@michalpasztamobica