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

fix: relay document listeners #6563

Open
wants to merge 13 commits into
base: next
Choose a base branch
from
Open

Conversation

bjoerge
Copy link
Member

@bjoerge bjoerge commented May 3, 2024

Description

This implements a relay approach for listener connections:

  • When we now set up a listener, we also schedule a new listener connection after somewhere between 12-19 minutes.
  • We’ll keep the old listener connected for 20s after the new one has connected and has received the welcome-event - (in case there’s in-flight messages yet to arrive).
  • There’s a distinct filtering on eventId so we avoid processing the same message twice.

These steps are repeated indefinitely (for as long as needed).

What to review

The intervals are currently hard coded, so the best way to test is probably to check out this branch, and edit the values here to something shorter (e.g. 10-20s with 4s overlap) and observe that a new listener is set up before the old one is shut down.

/** How long to wait after the first connection is set up to start the exchange */
exchangeWaitMin: 1000 * 60 * 12,
exchangeWaitMax: 1000 * 60 * 19,
/** How long should the overlap between the two listeners be */
exchangeOverLapTime: 1000 * 20,
/** If we're unable to set up the next listener within this time, we'll just continue with the current one */
exchangeTimeout: 1000 * 20,

It might be a bit hard to unpack the code, but I believe the logic is correct and there's tests to verify that it behaves correctly.

Since this can potentially make it easier to hit the the max number of concurrent connections allowed by browsers on http/1. I didn't include a config flag to disable this right now, but it should be quite straightforward to add a config flag if we wish to do so. For now, there's a timeout on the second listener that will cancel it if it's not able to connect within a certain time. If this happens, the first listener will keep runnning.

  • Since the server now should allow connections to live for a lot longer – should we wait for longer before exchanging the current one with a new one?

Testing

Added unit tests asserting that:

  • Listener setup, handoff and teardown works as it should
  • De-duping listener events based on eventId works
  • Timeout on "next" leg keeps the current
  • It waits for the first connection to be set up and have received the welcome event before scheduling the next one

Notes for release

N/A - It should be transparent for the user.

Copy link

vercel bot commented May 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview May 13, 2024 11:04am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 11:04am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 11:04am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 13, 2024 11:04am

Copy link
Contributor

github-actions bot commented May 3, 2024

No changes to documentation

Copy link
Contributor

github-actions bot commented May 3, 2024

Component Testing Report Updated May 13, 2024 11:09 AM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 33s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 31s 11 7 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 35s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 3s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 2s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 22s 9 0 0

jordanl17 and others added 8 commits May 8, 2024 10:51
* fix(studio): adding tooltip to read-only bool inputs

* fix(studio): testing for tooltip on boolean read-only inputs

* fix(studio): removing memoisation as it was useless
Co-authored-by: juice49 <1454914+juice49@users.noreply.github.com>
* feat: add canHandleIntent to S.component

* fix: properly type canHandleIntent

* Update packages/sanity/src/structure/structureBuilder/Component.ts

Co-authored-by: Ash <ash@sanity.io>

---------

Co-authored-by: Ash <ash@sanity.io>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
* feat(vision): add download as json/csv buttons

* fix(vision): use blob urls for downloads (#6213)

* fix(vision): use Translate component to avoid splitting i18n strings

* fix(vision): clean up i18n resources for result saving feature

---------

Co-authored-by: Espen Hovlandsdal <espen@hovlandsdal.com>
@bjoerge bjoerge force-pushed the sdx-1311/relay-document-listeners branch from d466e25 to 32fbe7d Compare May 8, 2024 19:54
@bjoerge bjoerge marked this pull request as ready for review May 8, 2024 19:57
@bjoerge bjoerge requested a review from a team as a code owner May 8, 2024 19:57
@bjoerge bjoerge requested a review from juice49 May 8, 2024 19:57
@bjoerge bjoerge force-pushed the sdx-1311/relay-document-listeners branch from 32fbe7d to 9acdb1f Compare May 8, 2024 19:57
juice49
juice49 previously approved these changes May 14, 2024
Copy link
Contributor

@juice49 juice49 left a comment

Choose a reason for hiding this comment

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

This looks great!

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

6 participants