Skip to content

fix: CountItems inflight correction skipped by a BigInt/Number type mix - #407

Merged
bert-e merged 1 commit into
development/1.17from
bugfix/S3UTILS-245/countitems-inflight-bigint-mix
Sep 18, 2026
Merged

bert-e merged 1 commit into
development/1.17from
bugfix/S3UTILS-245/countitems-inflight-bigint-mix

Conversation

@delthas

@delthas delthas commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

updateInflightDeltas throws on every completed count-items run on any platform with concurrent writes, and the inflight correction is then silently skipped for every bucket and account.

{"method":"updateInflightDeltas","errorString":"TypeError: Cannot mix BigInt and other types, use explicit conversions"}

Observed on a customer platform in two sosreports three months apart, one occurrence per completed run. An idle platform shows zero — consistent with the trigger.

Mechanism

  1. :963convertNumberToLong(metrics) turns every bigint into a BSON Long, so by the time updateInflightDeltas runs at :969 both usedCapacity.current and _inflightsPreScan are Long.
  2. :86_inflight comes from MongoDB, where promoteLongs defaults to true, so it is a plain Number. The subtraction is Number arithmetic and yields a Number.
  3. :19BigIntMax converts both operands to compare them, then returns the unconverted one, so a Number comes back out.
  4. :91BigInt(current) + <Number>TypeError.

Second path: _inflightsPreScan is only stored when non-zero (:414), so a bucket that only gained inflights during the scan gives 5000 - undefined = NaNBigInt(NaN)RangeError.

Both are caught at :122, logged once, and allMetrics is returned unmodified.

Fix

Convert at the two boundaries, and make BigIntMax return its converted operands so it cannot launder a type again. The correct pattern already existed at :1035, which reads the same field as BigInt(doc.usedCapacity._inflight.toString()).

The other ten BigIntMax call sites (:690-707, :725, :728) already pass BigInt values against 0n, so that change is a no-op for them.

Why it was never caught

The unit test stubbed the collection with _inflight: 3000n — a BigInt literal MongoDB cannot return, since nothing sets useBigInt64. With BigInt on both sides the arithmetic succeeded and the test passed.

That stub now uses a Number, and two new tests drive the real in-memory MongoDB without stubbing getCollection, so the driver's own conversions are exercised. Both fail on the parent commit with Expected 3900n, Received 1000n — the metric left uncorrected — and pass here.

Regression range

Correct when added (490de27, S3UTILS-163, 1.14.8) — it was written in defensive Number arithmetic. The BigInt migration (1460431, 1.14.18) replaced Math.max with BigIntMax and dropped the Number() / Long.fromNumber() coercions. Affected from 1.14.18 through 1.19.1.

Verification

yarn test:unit locally: 32 suites, 456 tests, all passing. eslint clean.

Issue: S3UTILS-245

`updateInflightDeltas` is reached after `convertNumberToLong` has turned
every metric into a BSON Long, and `_inflight` is read back from MongoDB
as a Number because `promoteLongs` defaults to true. Neither side of the
subtraction is a BigInt, so `BigIntMax` -- which compares as BigInt but
returned the unconverted operand -- handed a Number to
`BigInt(current) + inflight`, raising:

    TypeError: Cannot mix BigInt and other types, use explicit conversions

`_inflightsPreScan` is also only stored when non-zero, so a bucket which
only gained inflights during the scan produced `NaN` and a RangeError
from `BigInt(NaN)` instead.

Both are caught and logged, and the function then returns the metrics
unchanged, so the correction was applied to no bucket and no account:
`usedCapacity.current` silently excluded the inflights remaining after
the scan, and `_inflightsDelta` was never written.

Convert at the two boundaries and make `BigIntMax` return its converted
operands so it cannot launder a type again.

The existing unit test stubbed the collection with `_inflight: 3000n`, a
value MongoDB cannot return, which is why this was never caught; it now
uses a Number, and two tests exercise the real in-memory MongoDB so the
driver's own conversions are covered.

Issue: S3UTILS-245
@bert-e

bert-e commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Hello delthas,

My role is to assist you with the merge of this
pull request. Please type @bert-e help to get information
on this process, or consult the user documentation.

Available options
name description privileged authored
/after_pull_request Wait for the given pull request id to be merged before continuing with the current one.
/bypass_author_approval Bypass the pull request author's approval
/bypass_build_status Bypass the build and test status
/bypass_commit_size Bypass the check on the size of the changeset TBA
/bypass_incompatible_branch Bypass the check on the source branch prefix
/bypass_jira_check Bypass the Jira issue check
/bypass_peer_approval Bypass the pull request peers' approval
/bypass_leader_approval Bypass the pull request leaders' approval
/bypass_source_branch_lineage Bypass the cross-branch contamination check
/approve Instruct Bert-E that the author has approved the pull request. ✍️
/create_pull_requests Allow the creation of integration pull requests.
/create_integration_branches Allow the creation of integration branches.
/no_octopus Prevent Wall-E from doing any octopus merge and use multiple consecutive merge instead
/unanimity Change review acceptance criteria from one reviewer at least to all reviewers
/wait Instruct Bert-E not to run until further notice.
Available commands
name description privileged
/help Print Bert-E's manual in the pull request.
/status Print Bert-E's current status in the pull request.
/clear Remove all comments from Bert-E from the history TBA
/retry Re-start a fresh build TBA
/build Re-start a fresh build TBA
/force_reset Delete integration branches & pull requests, and restart merge process from the beginning.
/reset Try to remove integration branches unless there are commits on them which do not appear on the source branch.

Status report is not available.

@scality scality deleted a comment from bert-e Sep 17, 2026
@bert-e

bert-e commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Request integration branches

Waiting for integration branch creation to be requested by the user.

To request integration branches, please comment on this pull request with the following command:

/create_integration_branches

Alternatively, the /approve and /create_pull_requests commands will automatically
create the integration branches.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.32%. Comparing base (c318e92) to head (a9008ef).

Additional details and impacted files
@@                 Coverage Diff                  @@
##           development/1.17     #407      +/-   ##
====================================================
+ Coverage             45.28%   45.32%   +0.04%     
====================================================
  Files                    88       88              
  Lines                  6486     6489       +3     
  Branches               1360     1363       +3     
====================================================
+ Hits                   2937     2941       +4     
+ Misses                 3503     3502       -1     
  Partials                 46       46              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@delthas

delthas commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

/approve

@delthas

delthas commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

!done 2h

@bert-e

bert-e commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Integration data created

I have created the integration data for the additional destination branches.

The following branches will NOT be impacted:

  • development/1.13
  • development/1.14
  • development/1.15
  • development/1.16
  • development/1.4
  • development/1.7

You can set option create_pull_requests if you need me to create
integration pull requests in addition to integration branches, with:

@bert-e create_pull_requests

The following options are set: approve

@bert-e

bert-e commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

I have successfully merged the changeset of this pull request
into targetted development branches:

  • ✔️ development/1.17

  • ✔️ development/1.18

  • ✔️ development/1

The following branches have NOT changed:

  • development/1.13
  • development/1.14
  • development/1.15
  • development/1.16
  • development/1.4
  • development/1.7

This pull request did not target the following hotfix branch(es) so they
were left untouched:

  • hotfix/1.14.0

Please check the status of the associated issue S3UTILS-245.

Goodbye delthas.

The following options are set: approve

@bert-e
bert-e merged commit a9008ef into development/1.17 Sep 18, 2026
15 checks passed
@bert-e
bert-e deleted the bugfix/S3UTILS-245/countitems-inflight-bigint-mix branch September 18, 2026 10:11
@delthas

delthas commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

S3UTILS-245: logged 2h; transitioned to Done (Fixed)

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.

4 participants