Repository navigation
sdk: retain reconnect requests across connection task teardown - #1479
erskingardner wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Retain both changelog entries while incorporating the merged COUNT and waiter fixes from upstream master.
Record the connection count for each long-lived subscription so a new session restores it even when it starts in the same second. Ref #1479 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Keep one task per relay and retain connection requests while an old WebSocket closes. Share connection outcomes between `Relay::try_connect` callers and stop the task on ban, shutdown or the last Relay drop. Replaces #1479 Pull-Request: #1491 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
|
Can this one be closed now @yukibtc seems like it was incorporated in another PR? |
Yeah, but before closing this I'll wait that the other one will be merged. |
Keep one task per relay and retain connection requests while an old WebSocket closes. Share connection outcomes between `Relay::try_connect` callers and stop the task on ban, shutdown or the last Relay drop. Replaces #1479 Pull-Request: #1491 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
|
@erskingardner, if you get the chance, could you give a try to #1491? It should behave in the same way of this one. I've just rebased it on master branch, so includes also #1483 |
|
I'll have a look now. |
|
Thanks @yukibtc. I tried #1491 (31a0237) against what #1479 was fixing, and it covers our cases:
I also ran two tests from #1479 against #1491. Both pass, and they could be worth bringing over since #1491 doesn't test either case:
There's one issue we hit on #1491 (I haven't checked whether it was already on master): a REQ queued while the relay is disconnected gets sent twice after reconnect. This happens with a plain Closing #1479 once #1491 merges is fine with me. For context, a few more fork changes are still keeping us off upstream, and I'll open separate PRs for them:
|
|
Quick follow-up on the duplicate REQ: I checked and it's already on master too, so it's not a regression from #1491 and doesn't need to block it. Repro (loopback relay that answers a repeated subscription id with
I'll open a small PR with the fix and this test. Want it based on |
Keep one task per relay and retain connection requests while an old WebSocket closes. Share connection outcomes between `Relay::try_connect` callers and stop the task on ban, shutdown or the last Relay drop. Replaces #1479 Pull-Request: #1491 Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Thanks, added at #1491
Thanks, I've just merged #1491 so it can be based on |
When `subscribe()` is called while disconnected, its REQ stays in the queue. On reconnect, `resubscribe()` adds a second REQ because the subscription still records the previous connection count. Record the next connection count for REQs queued while disconnected. Handle REQs sent through `send_msg()` the same way. Ref nostrdevkit#1479 (comment) Pull-Request: nostrdevkit#1492 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Description
A reconnect requested after
disconnect()can be lost while the previous connection task is still exiting, leaving the relay Pending without a running task. Subscription restoration also uses second-resolution timestamps, so two connections within one second can leave long-lived subscriptions inactive.Serialize connection-task ownership and retain a reconnect request until the old task releases it. Reserve ownership before
try_connectdials; cancellation releases that reservation, and a superseded dial cannot publish Connected. Clear stale termination permits before starting a replacement task. Track subscriptions by successful connection generation so immediate reconnect restores them reliably.Notes to the reviewers
The public API signatures are unchanged. Disconnect/Terminated describe a termination request, not a task-exit barrier; the documentation now states this. Ban and shutdown cancel pending reconnects.
Deterministic teardown barriers exercise reconnect with automatic retries enabled and disabled, concurrent connect calls, stale termination permits, shutdown cancellation, and
try_connectownership conflicts. Additional regressions verify state changes while the admission policy is pending and release of connection ownership on dial cancellation or timeout. Loopback tests verify restored subscriptions and independent NIP-42 signers across reconnect.Validation:
just fmtand the completejust precommitpassed locally on the pinned toolchain, including SDK tests with default and local-relay features, the configured WASM checks, Clippy, and documentation checks.Checklist
CHANGELOG.md(if applicable)