-
Notifications
You must be signed in to change notification settings - Fork 49
feat: Reliable Channel: Status Sync, overflow protection, stop TODOs #2729
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d851722
feat(sds): messages with lost deps are delivered
fryorcraken 87dc5fa
fix(sds): avoid overflow in message history storage
fryorcraken 682aeee
feat(reliable-channel): Emit a "Synced" Status with message counts
fryorcraken d3a1ac7
fix: clean up subscriptions, intervals and timeouts when stopping
fryorcraken 4dde565
chore: extract random timeout
fryorcraken 2d572c9
fix rebase
fryorcraken 1d58aee
revert listener changes
fryorcraken 443264e
typo
fryorcraken a82b779
Ensuring no inconsistency on missing message
fryorcraken 025dfa2
test: streamline, stop channels
fryorcraken 6a744e1
clear sync status sets when stopping channel
fryorcraken 3eaaea0
prevent sync status event spam
fryorcraken 69121b8
test: improve naming
fryorcraken a2eaec4
try/catch for callback
fryorcraken 359ce94
encapsulate/simplify reliable channel API
fryorcraken 0e5e912
sanity checks
fryorcraken 339e26e
test: ensure sync status cleanup
fryorcraken 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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,8 @@ | ||
| export { ReliableChannel, ReliableChannelOptions } from "./reliable_channel.js"; | ||
| export { ReliableChannelEvents, ReliableChannelEvent } from "./events.js"; | ||
| export { | ||
| StatusEvent, | ||
| StatusEvents, | ||
| StatusDetail, | ||
| ISyncStatusEvents | ||
| } from "./sync_status.js"; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { Logger } from "@waku/utils"; | ||
|
|
||
| const log = new Logger("sdk:random-timeout"); | ||
|
|
||
| /** | ||
| * Enables waiting a random time before doing an action (using `setTimeout`), | ||
| * with possibility to apply a multiplier to manipulate said time. | ||
| */ | ||
| export class RandomTimeout { | ||
| private timeout: ReturnType<typeof setTimeout> | undefined; | ||
|
|
||
| public constructor( | ||
| /** | ||
| * The maximum interval one would wait before the call is made, in milliseconds. | ||
| */ | ||
| private maxIntervalMs: number, | ||
| /** | ||
| * When not zero: Anytime a call is made, then a new call will be rescheduled | ||
| * using this multiplier | ||
| */ | ||
| private multiplierOnCall: number, | ||
| /** | ||
| * The function to call when the timer is reached | ||
| */ | ||
| private callback: () => void | Promise<void> | ||
| ) { | ||
| if (!Number.isFinite(maxIntervalMs) || maxIntervalMs < 0) { | ||
| throw new Error( | ||
| `maxIntervalMs must be a non-negative finite number, got: ${maxIntervalMs}` | ||
| ); | ||
| } | ||
| if (!Number.isFinite(multiplierOnCall)) { | ||
| throw new Error( | ||
| `multiplierOnCall must be a finite number, got: ${multiplierOnCall}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Use to start the timer. If a timer was already set, it deletes it and | ||
| * schedule a new one. | ||
| * @param multiplier applied to [[maxIntervalMs]] | ||
| */ | ||
| public restart(multiplier: number = 1): void { | ||
| this.stop(); | ||
|
|
||
| if (this.maxIntervalMs) { | ||
| const timeoutMs = Math.random() * this.maxIntervalMs * multiplier; | ||
|
|
||
| this.timeout = setTimeout(() => { | ||
| try { | ||
| void this.callback(); | ||
| } catch (error) { | ||
| log.error("Error in RandomTimeout callback:", error); | ||
| } | ||
| void this.restart(this.multiplierOnCall); | ||
| }, timeoutMs); | ||
| } | ||
| } | ||
|
|
||
| public stop(): void { | ||
| if (this.timeout) { | ||
| clearTimeout(this.timeout); | ||
| this.timeout = undefined; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
why so? test is passing on master
Uh oh!
There was an error while loading. Please reload this page.
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.
My new tests aren't yet on master and they don't pass with this enabled because
setIntervaldoes not work any more once with the code in this test.Tests on master aren't passing either: #2648
I have spent half a day on this and I can guarantee that the code in this test pollutes the global state. It is not being restored (at least with node 22.17.0, I can try with other node versions in a couple of weeks).