Skip to content

sdk: avoid deprecated AtomicUsize::fetch_update - #1496

Merged
yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:sdk/fix-fetch-update-deprecation
Oct 19, 2026
Merged

yukibtc merged 1 commit into
nostrdevkit:masterfrom
erskingardner:sdk/fix-fetch-update-deprecation

Conversation

@agent-p1p

Copy link
Copy Markdown
Contributor

Problem

The "Check stable" CI job fails on master (de3031a) and on the open PRs #1494 and #1495. It builds with -D warnings, and Rust 1.99 deprecates AtomicUsize::fetch_update (renamed to try_update), which PendingReqCounter::decrement uses. Nobody using the crate is affected, but the failing job hides real failures on new PRs.

Fix

Replace the fetch_update call with the compare-and-swap loop it performs internally. try_update is newer than the 1.85 MSRV, so it can't be used yet, and writing out the loop avoids suppressing the lint. The decrement still saturates at zero.

Notes to the reviewers

  • Checked locally with rustc 1.99.0, the version the failing job used. CARGO_BUILD_RUSTFLAGS="-D warnings" cargo +1.99.0 build --workspace --all-targets and cargo +1.99.0 clippy --all-targets -- -D warnings both pass. On master, the build fails with the same error as CI.
  • The existing pending_req_counter_does_not_underflow and pending_req_counter_tracks_requests_until_all_are_dropped tests cover the behaviour. just precommit passes.
  • No changelog entry, since there is no user-visible change.

Checklist

  • I followed the contribution guidelines
  • I updated the relevant CHANGELOG.md (if applicable)
  • I understand and can explain all code in this PR

🤖 Generated with Claude Code

Rust 1.99 deprecates `fetch_update` in favor of `try_update`, so the
"Check stable" CI job, which builds with `-D warnings`, fails on
`PendingReqCounter::decrement`. `try_update` is above the 1.85 MSRV,
so write out the compare-and-swap loop that `fetch_update` performs
instead. The decrement still saturates at zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
nostr-sdk/src/relay/inner.rs 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@agent-p1p

Copy link
Copy Markdown
Contributor Author

@yukibtc The loop is only needed because of the MSRV. try_update, the replacement, has been stable since Rust 1.95 (fetch_update was deprecated in 1.99), while the workspace MSRV is 1.85. If you're willing to raise the MSRV to 1.95, the cleaner fix is a one-line rename to try_update, and I'm happy to switch this PR to that. If not, this version keeps 1.85 working without silencing the lint.

@yukibtc
yukibtc merged commit fac19eb into nostrdevkit:master Oct 19, 2026
43 checks passed
agent-p1p added a commit to erskingardner/rust-nostr that referenced this pull request Oct 19, 2026
Catch up with the `AtomicUsize::fetch_update` deprecation fix
(nostrdevkit#1496), which unbreaks the
"Check stable" CI job, and the nostr-connect API rework
(nostrdevkit#1494). The merge has no
conflicts, and the fork's delta against upstream is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agent-p1p
agent-p1p deleted the sdk/fix-fetch-update-deprecation branch October 19, 2026 15:03
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.

2 participants