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

endpoint: Try immediate send before queing pending #447

Merged
merged 2 commits into from
Nov 7, 2021

Conversation

kennylevinsen
Copy link
Contributor

sendWhenActive always queues the request for next time the pending queue
was flushed. This has the unfortunate side-effect of delaying sends
until next time the end device talks, even if the device is currently
active.

Instead, try to send the request immediately, and only fall back to the
pending queue if that failed or if something was already queued.

Notes:

  • The detection for transaction expired is a little rough. We also still go through normal retry first, which might be a bit wasteful.
  • We will still fail the entire pending queue if we try to send it at a bad time, instead of detecting this and putting them back in the queue.

return await func();
} catch(error) {
// TODO: Improve check for expired transaction
if (!sendWhenActive || error.code !== 240) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not rely on the error code here, they might be different across different adapters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we formalize an error type, or should we just throw it in pending regardless of the error when sendWhenActive is set?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • sendWhenActive == false -> throw error
  • sendWhenActive == true -> dont throw error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and expanded the tests to cover the new cases.

} else {
return func();
private async sendRequest<Type>(func: () => Promise<Type>, sendWhenActive: boolean): Promise<Type> {
if (this.pendingRequests.length === 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the request only send when pendingRequests are empty? I would expect that a request with sendWhenActive = false would always be send directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, true. I'll change that.

The idea was that if things had started queuing, we'd keep queuing for some amount of ordering, but it does behave a bit odd of you're asking for no queueing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split off the queuing to avoid making things too ugly.

@kennylevinsen
Copy link
Contributor Author

Note: I'm currently missing test coverage, will get that sorted tomorrow.

@kennylevinsen kennylevinsen force-pushed the immediate-send branch 2 times, most recently from ae33e0c to d9f8430 Compare November 6, 2021 15:01
@kennylevinsen
Copy link
Contributor Author

Test coverage fixed. Had some trouble getting the timing right in the test (sending data to wake things up after the request has been queued, but before we end up stalling on an await), but found a solution that's good enough.

@Koenkk
Copy link
Owner

Koenkk commented Nov 7, 2021

@kennylevinsen I've rebased it after #446 but now the coverage is failing, could you check this?

sendWhenActive always queues the request for next time the pending queue
was flushed. This has the unfortunate side-effect of delaying sends
until next time the end device talks, even if the device is currently
active.

Instead, try to send the request immediately, and only fall back to the
pending queue if that failed or if something was already queued.
@kennylevinsen
Copy link
Contributor Author

Yeah, the new checkin test had to be adjusted slightly for the sendWhenActive behavior change. Fixed!

@Koenkk
Copy link
Owner

Koenkk commented Nov 7, 2021

Awesome, thanks! 🏅

@Koenkk Koenkk merged commit b5ed3f6 into Koenkk:master Nov 7, 2021
@kennylevinsen kennylevinsen deleted the immediate-send branch November 7, 2021 18:19
@kennylevinsen kennylevinsen mentioned this pull request Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants