-
Notifications
You must be signed in to change notification settings - Fork 7
transport: sar: skip ACK resend when not connected #210
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
Draft
szczys
wants to merge
1
commit into
main
Choose a base branch
from
szczys/sar-ack-not-connected
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6
−0
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@szczys what case are you seeing us encountering this scenario? I would expect that if the connection is lost we would be closing the receiver and canceling the work queue. However, if we do not close the receiver, then I suspect that we would want to not just ignore the failed ack send, but go ahead and terminate the transfer.
In short, if this situation is unrecoverable, then I would imagine that we should abort the transfer entirely rather than just ignoring a failure to ack. If the situation is recoverable, then we want to keep acking.
Or is this just to account for the case in which this ack is already in progress when the work queue is canceled?
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.
I'll get back to you on that. This may have been cause by other issues I'm currently troubleshooting.
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.
I am no longer able to reproduce this after fixing other concurrency issues I was having, but let me describe the behavior:
This code is running on the device and if the broker disconnects,
close()will be called in theBLE_GAP_EVENT_DISCONNECTcase ofpouch_gatt_gap_event. So you're right that the transfer needs to be aborted and that is indeed how the design works.However, I was still occassionally seeing a situation where the -ENOTCONN was returned by the NimBLE stack which led to the schedule_ack() being called, starting a 1Hz loop of error messages: work_handler -> -ENOTCONN -> reschedule
One possibility is that the concurrency issues I was resolving were corrupting the memory and causing ACK to run even though a disconnect had happened.
However, the ACK is put on a delayable work queue that is running at a lower priority than some of the other threads so here's a legitimate scenarion that could happen:
If this is actually what's happening, it makes a case for fixing the port so that enqueued work can be removed. However, this is a significantly complex functionality to add so I'm not advocating for it.
Actually, now that I think of it, there's also a small sliver of time in the Zephyr delayable work where the same could happen. It's after the queued work has been popped from the queue but has not yet finished processing. If the work queue is preempted, then the cancel will not stop the delayable ACK work from running once focus is back on the workq thread and we'll be in the same loop.
Thank you for coming to my Ted talk.
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.
@szczys thanks for writing this up! We chatted offline and the Zephyr example of work in progress was the one that I was thinking of, but it seems as though the ESP-IDF case is potentially even more likely. Regardless, my primary concern is silently not rescheduling the ack, which effectively will halt progress, without informing the transport (bearer). I'm also somewhat concerned about
pouch_bearer_send()failing with an error other than-ENOTCONN, and us finding ourselves in this same ack loop.To address the former, I think we could call
end()here to signal to the bearer that the transfer is being aborted. To address the latter, I think it could make sense to only reschedule the ack in the event that the error is-EAGAIN(i.e. invert the error check logic here), and assume that if the bearer can't send and doesn't return-EAGAINthen we should abort the transfer.