Closed dadepo closed 4 years ago
Version 1.6.38 was released 1 year ago in December 2018.
It seems that the code you are running was close to reaching the memory limit, and some small change in the library pushed it over the limit.
Could you share the code you are running?
So I was able to narrow down the part of the test code that triggers this behaviour. It can be found here https://github.com/ip-num/ip-num/blob/69088bfa38f7a84ffad7b38d4da66b1859bbf3a2/spec/IPv6CidrRangeTest.ts#L51
In summary this is what the test is doing:
IPv6
with a certain sizeretrieve size
retrieve size
out of the IPV6
IPv6
The size being used for this test is (2 ^ 82)
Observation using the previous (< 1.6.37) version of big-integer:
IPV6.getSize().valueOf() prints 4.835703278458517e+24 // js number IPV6.getSize().plus(1).valueOf() prints 4.835703278458517e+24 // js number
and
IPV6.getSize() prints:
Integer {
value: [ 0, 5851700, 7032784, 4835 ],
sign: false,
isSmall: false
}
and
IPV6.getSize().plus(1) prints:
Integer {
value: [ 8824704, 5851669, 7032784, 4835 ],
sign: false,
isSmall: false
}
and
IPV6.getSize().plus(1).greater(IPV6.getSize())
returns true, which is expected
Observation using the previous (>= 1.6.37) version of big-integer:
IPV6.getSize().valueOf() prints 4.835703278458517e+24 // js number IPV6.getSize().plus(1).valueOf() prints 4.835703278458517e+24 // js number
and
IPV6.getSize() prints:
Integer { value: 4835703278458516698824704n }
and
IPV6.getSize().plus(1) prints:
Integer { value: 4835703278458516698824704n }
and
IPV6.getSize().plus(1).greater(IPV6.getSize())
now returns false, which is not desired, which then lead the code to fill an array up with (2 ^ 82) instances of an object, and hence the crash.
So I guess the question is, why has the .greater
change? is this something I am doing wrong?
Why does IPV6.getSize().plus(1)
returns the same value in your test?
Why does IPV6.getSize().plus(1) returns the same value in your test?
Exactly the same question I asked myself...
But I noticed that, even though same value are also printed in versions < 1.6.37, the greater than checks behaves as I would expect it.
@dadepo ,
But I noticed that, even though same value are also printed in versions < 1.6.37, the greater than checks behaves as I would expect it.
You are saying, that it is valueOf
returns the same values, but this is because it is converted to the number here. And you are saying, that the arrays in <1.6.37 are different and in the new version the internal value is the same, which is really strange to me.
I would try to debug your code trying to check if 4835703278458516698824704n+1n
works correctly, then trying to double check again the test and by trying to set a break point before the check.
I cannot reproduce with some simple test. And I don't know how to run the tests in your lib.
I cannot reproduce with some simple test. And I don't know how to run the tests in your lib.
I pushed the branch I used for poking around. https://github.com/ip-num/ip-num/tree/debugging-oom-error it has all the console logs in both the test and the implementation.
If you can out the branch and run npm run test
, you should be able to see the output. (you need to have TypeSript installed though).
Only one test will run. You can the change the big-integer version in package.json, rerun the test and see the output also.
Hopefully this helps...
I was able to isolate the reproduction steps. If you create a node project and run the code below in the terminal, you will see the behaviour I encountered reproduced.
var bigInt = require("big-integer");
let v1 = bigInt(2).pow(82);
let v1_plus_one = v1.plus(1)
console.log("To string representation of valueOf:")
console.log(v1.valueOf())
console.log(v1_plus_one.valueOf())
// making an instance of bigInt again from v1 after adding 1 to it
v1_plus_one2 = bigInt(v1_plus_one.valueOf())
// Expect this to print true, but it prints false
console.log(v1_plus_one2.greater(v1))
my guess is conversion to number (via valueOf) and then constructing the bigInt again leads to loss in precision? Would appreciate if you can help confirm that this is what I am doing wrong and I can change my code not to.
UPDATE
It seems this is the case. console.log(v1_plus_one.greater(v1))
prints true as expected. Once I get confirmation from your end regarding this behaviour and it not being an issue... I shall close the ticket. But it would be interesting to know why this never caused any problems in previous versions.
Yes, valueOf does conversion to number with precision loss.
Any thoughts on why this never caused any problems in previous versions?
it is hard to say - I cannot find it from the code
Maybe it might be interesting to know that, this changed in behaviour started with the 1.6.37 release, which was the release that added the ability for the library to act as a polyfill to native BigInt https://github.com/peterolson/BigInteger.js/releases/tag/v1.6.37
npm version: 6.13.4
I am trying to upgrade from v1.6.28 to 1.6.48 and when I run the test for the project, I get the following errors:
I was able to narrow this down to version
1.6.37
in the sense that version1.6.36
and below runs fine, but from version1.6.37
and above, it does not.