Fix fallback pull race after abort #167
Reference in New Issue
Block a user
Delete Branch "nayan9617/flotilla:fix/pull-fallback-abort-race"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR fixes the sleep/wake sync leak by stopping stale async work in the fallback pull path from continuing after abort.
The investigation showed that welshman cleanup was already completing correctly, so the bug was not in request teardown. The real problem was in the async flow inside sync.ts: pullAndListen() was starting pullWithFallback() without awaiting it, and pullOneWithFallback() could continue past controller.abort() after loadRelay() resolved. That allowed the chain to reach Difference creation and fallback request() calls even though teardown had already won.
Fixes #111
What changed:
-Added an early signal.aborted guard at the top of pullOneWithFallback().
-Kept the abort check before Difference creation so no new listener work starts after teardown.
-Kept the abort check before the fallback request() call so the relay request is not re-issued after abort.
-Added an early guard in pullAndListen() so a stale call does not start the async chain at all.
-Kept the visibility lifecycle support already in place via state.ts.
Validation:
pnpm run check passed with 0 errors and 0 warnings.
Can you add .next to gitignore and remove it from the commit?
Otherwise this looks decent, but it occurs to me we probably actually want to keep syncing in the background, because that's how notifications get triggered. So I think the document visibility stuff is actually not something we should add. Sorry I didn't realize that earlier.
@@ -159,0 +160,4 @@export const documentVisibility = readable<DocumentVisibilityState>(typeof document !== "undefined" ? document.visibilityState : "visible",set => {if (typeof document === "undefined") returnNo need to check for document, this project doesn't do SSR
@@ -6,6 +6,7 @@ import {PollResponse} from "nostr-tools/kinds"import {getListTags,getRelayTagValues,type List,Use
import typerather than mixing type/variable imports@@ -240,3 +241,1 @@loadFeedsForPubkey($userRelayList.event.pubkey)}})const syncRelayList = ($userRelayList: List | undefined) => {You can use
PublishedListhere for a slightly more narrow type@@ -245,3 +257,2 @@for (const pubkeys of chunk(10, get(bootstrapPubkeys))) {// This isn't urgent, avoid clogging other stuff upawait sleep(1000)void (async () => {This actually changes the behavior to flood relays with requests. This needs to be a trickle in the background to prevent interrupting other requests. If we need to cancel it, then we should add that explicitly.
@@ -260,0 +293,4 @@},)const unsubscribeFollows = derived([userFollowList, documentVisibility], identity).subscribe(Instead of derived/identity you can use
mergedfrom@welshman/store.next is still in the diff
Actually that was due to earlier commit, and despite adding it to .gitignore it was still there. Though, I've now untracked those files.
d0e23b605cto3dd5a0915fPerfect, thanks!
Hey @hodlbod, I wasn’t experiencing any logging-related hangs before, but after pulling this merge I’m now running into an issue where it gets stuck.
Could you please take a look? I’ve attached a video for reference.
update: It worked, but it took quite a while.
hello @userAdityaa thanks for letting us know. Let me check if this could anyway affect logging delays.
The login issue is unrelated to this PR, it looks like one of the signers is timing out. I'll look into it.