Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

ipfs-http-client & go-ipfs - BigInt issue with stats.bw() #3782

@jurelik

Description

@jurelik
  • Version:
    ipfs-http-client: 51.0.1
    go-ipfs: 0.9.1

  • Platform:
    Darwin jure.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64

  • Subsystem:
    stats.bw

Severity:

Medium - A non-essential functionality does not work, performance issues, etc.

Description:

I suspect this issue is related to #3726 and it's subsequent fix in #3735. I'm getting the same error as the user in the OP, namely:

The number xxxx.yyyy cannot be converted to a BigInt because it is not an integer

I have fixed the issue by changing the code in ipfs-http-client/src/stats/bw.js by following the lead in #3735 like so:

  async function * bw (options = {}) {
    const res = await api.post('stats/bw', {
      timeout: options.timeout,
      signal: options.signal,
      searchParams: toUrlSearchParams(options),
      headers: options.headers,
      transform: (stats) => ({
        totalIn: BigInt(Math.round(stats.TotalIn)),
        totalOut: BigInt(Math.roundstats.TotalOut)),
        rateIn: BigInt(Math.round(stats.RateIn)),
        rateOut: BigInt(Math.round(stats.RateOut))
      })
    })

    yield * res.ndjson()
  }

This works fine as a quick fix but I'm not sure if:

  • Math.Round is the way you want to approach solving this
  • that's an issue that should be solved in go-ipfs or ipfs-http-client.

If it's something you would like to have fixed in ipfs-http-client I'd be happy to submit a PR, but I can't help you with the golang side of things. Any advice would be much appreciated!

Steps to reproduce the error:

Set up ipfs-http-client to work with the go-ipfs npm package and run:

for await (const stats of ipfs.stats.bw({ poll: true, interval: '1s' })) {
  console.log(stats.rateIn);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    need/triageNeeds initial labeling and prioritization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions