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

feat: two explicit queues for session work #538

Closed
wants to merge 14 commits into from

Conversation

SgtPooki
Copy link
Member

@SgtPooki SgtPooki commented May 16, 2024

Title

feat: two explicit queues for session work

Description

This PR originally aimed to fix the infinite loop we hit when we were only getting a single provider (this only occurring in test envs that i'm aware of, but certainly possible elsewhere). However, it's now been updated to refactor the provider finding and querying logic so that it's a little more obvious what is happening.

Notes & open questions

A few main things that change with this PR:

  1. We are now explicitly kicking off the findProviders task when findProviders is done (idle event)
  2. We are only querying providers when we get a provider event, or when an existing session is queried with a new cid (we will query any currently known and non-evicted providers).
    • The latter was existing code that was always ran, but is no longer needed for non-child-item-retrieve events since we query on provider events now
  3. We use the same found < count logic to determine if we found enough providers, or throw an error
  4. On findProvider job error (failure event), we set a flag indicating that we failed to find more providers.
    • if queryProviders job is running, we do not throw this error, because queryProviderQueue idle will handle when triggered.
  5. on queryProvider idle
    • if we found the block: we don't start up any more work
    • if signal aborted, we reject the retrieve promise
    • if foundProviders errored, we reject the retrieve promise: new error that we're done querying providers and could not get the block
    • if findProviders queue is empty, we kick it off again (this case covers the child-item-t-retrieve event where findProvidersQueue idle would have already been emitted on root-CID query)

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if necessary (this includes comments as well)
  • I have added tests that prove my fix is effective or that my feature works

@SgtPooki SgtPooki changed the title fix: single found provider does not infinitely loop fix: single found provider does not infinitely loop [WIP] May 16, 2024
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review

packages/utils/test/abstract-session.spec.ts Outdated Show resolved Hide resolved
@SgtPooki SgtPooki marked this pull request as ready for review May 16, 2024 23:31
@SgtPooki SgtPooki requested a review from a team as a code owner May 16, 2024 23:31
@SgtPooki SgtPooki changed the title fix: single found provider does not infinitely loop [WIP] fix: single found provider does not infinitely loop May 17, 2024
@SgtPooki SgtPooki self-assigned this May 17, 2024
@SgtPooki SgtPooki changed the title fix: single found provider does not infinitely loop feat: two explicit queues for session work May 20, 2024
Copy link
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

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

self review. ready for @achingbrain

packages/utils/src/abstract-session.ts Outdated Show resolved Hide resolved
packages/utils/src/abstract-session.ts Outdated Show resolved Hide resolved
})
queue.addEventListener('error', () => {})
Copy link
Member Author

Choose a reason for hiding this comment

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

not sure if adding this empty error handler is necessary?

@SgtPooki
Copy link
Member Author

SgtPooki commented Aug 1, 2024

run benchmarks to see if regression or improvement.

@SgtPooki SgtPooki closed this Nov 12, 2024
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.

1 participant