Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oj.dump throws RangeError for Time value (Windows only?) #485

Closed
aharpervc opened this issue Jul 16, 2018 · 20 comments
Closed

Oj.dump throws RangeError for Time value (Windows only?) #485

aharpervc opened this issue Jul 16, 2018 · 20 comments

Comments

@aharpervc
Copy link

I'm seeing an error dumping a Time value. The error is:

RangeError: bignum too big to convert into `long'

I tested the following configurations:

error with:

  • 2.4.3 i386-mingw32
  • 2.5.1 i386-mingw32
  • 2.5.1 x64-mingw32

no error with

  • 2.4.3 x86_64-linux
  • 2.5.1 x86_64-linux

simple repro:

# gem install oj -v '3.6.4'
require 'oj'
puts Oj::VERSION

x = {"duration"=>Time.parse("1900-01-01 00:18:59 UTC")}
Oj.dump x
# => RangeError: bignum too big to convert into `long'
# OR => {"duration":{"^t":-2208987661.000000000}}
@ohler55
Copy link
Owner

ohler55 commented Jul 16, 2018

I'm not setup for windows. Would you be able to test changes for me?

@aharpervc
Copy link
Author

Potentially yes, although I do see that you have Windows CI set up so hopefully that will help as well

@ohler55
Copy link
Owner

ohler55 commented Jul 17, 2018

I checked in a win-time branch that I think fixes the issue. It passed appveyor anyway. Let me know if it works on your system please.

@aharpervc
Copy link
Author

The new test is failing on the branch:

Error:
Juice#test_time_neg:
RangeError: bignum too big to convert into `long'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `dump'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `test_time_neg'

However, I actually have test failures on master as well- all time stuff. So clearly something is weird in my environment that is affecting this.

$ ruby .\test\tests.rb
Run options: --seed 7102

# Running:

............................................................................................................................................................................................................F

Failure:
CustomJuice#test_time [C:/Users/aharper/workspace/oj/test/test_custom.rb:350]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
 # encoding: US-ASCII
-"2018-07-17 09:46:01 -0400"
+"2018-07-17 09:46:01 +0000"



bin/rails test C:/Users/aharper/workspace/oj/test/test_custom.rb:319

............................................F

Failure:
ObjectJuice#test_ruby_time [C:/Users/aharper/workspace/oj/test/test_object.rb:503]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:495

.....F

Failure:
ObjectJuice#test_ruby_time_12345 [C:/Users/aharper/workspace/oj/test/test_object.rb:522]:
Expected: 1420481527
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:513

..................F

Failure:
ObjectJuice#test_xml_time [C:/Users/aharper/workspace/oj/test/test_object.rb:468]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:460

..............................................................................................................................................................................

Finished in 2.626605s, 170.9431 runs/s, 313.3322 assertions/s.
449 runs, 823 assertions, 4 failures, 0 errors, 0 skips

@ohler55
Copy link
Owner

ohler55 commented Jul 17, 2018

It looks like a timezone issue creeping in that did not show up on appveyor. I'll look into it and see if I can add some debug info on the branch.

I'd like to figure out how you environment is different from appveyor as well.

@ohler55
Copy link
Owner

ohler55 commented Jul 18, 2018

I turned on trace for the custom test. Will focus on that one until I figure out what is going on. I'm going to make a guess that you are in either a +8 or -8 timezone. Is that correct?

@aharpervc
Copy link
Author

No, I'm US EDT (-4)

Time.now
=> 2018-07-18 10:36:36 -0400

@ohler55
Copy link
Owner

ohler55 commented Jul 21, 2018

It has been a busy week. Anyway, I checked in a version with some extra print statements to narrow down where in the custom test the failure is occurring. There are 4 possible test cases. Please let me know what the results are. This is the first step of several I'm afraid since I can't reproduce it here.

@ohler55
Copy link
Owner

ohler55 commented Jul 25, 2018

Where you able to run the tests?

@aharpervc
Copy link
Author

I had some time to revisit this. Still seeing test failures, but also seeing your diagnostic output. Here's the latest compile + test run. I still have no idea why my environment would be contributing to this.

$ ruby .\test\tests.rb
Run options: --seed 45161

# Running:

..............................................................................F

Failure:
ObjectJuice#test_ruby_time_12345 [C:/Users/aharper/workspace/oj/test/test_object.rb:522]:
Expected: 1420481527
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:513

.......................................F

Failure:
ObjectJuice#test_xml_time [C:/Users/aharper/workspace/oj/test/test_object.rb:468]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:460

....................F

Failure:
ObjectJuice#test_ruby_time [C:/Users/aharper/workspace/oj/test/test_object.rb:503]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:495

.....................................................................................................................................................................................E

Error:
Juice#test_time_neg:
RangeError: bignum too big to convert into `long'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `dump'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `test_time_neg'


bin/rails test C:/Users/aharper/workspace/oj/test/test_various.rb:410

...................................................................................*** test time: 2018-07-25 15:02:08 -0400
{
  "^o":"Time",
  "time":1532545328.053397000
}
{
  "^o":"Time",
  "time":1532545328.053397000e-14400
}
{
  "^o":"Time",
  "time":"2018-07-25T15:02:08.053397000\u000045:04"
}
F

Failure:
CustomJuice#test_time [C:/Users/aharper/workspace/oj/test/test_custom.rb:351]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
 # encoding: US-ASCII
-"2018-07-25 15:02:08 -0400"
+"2018-07-25 15:02:08 +0000"



bin/rails test C:/Users/aharper/workspace/oj/test/test_custom.rb:319

............................................

Finished in 0.811580s, 554.4742 runs/s, 1014.0717 assertions/s.
450 runs, 823 assertions, 4 failures, 1 errors, 0 skips

@ohler55
Copy link
Owner

ohler55 commented Jul 25, 2018

Interesting result on the 3rd custom test. That's helpful. Looks like there is still a conversion problem showing up in the object test too. Thanks. I'll have another attempt tonight.

@ohler55
Copy link
Owner

ohler55 commented Jul 25, 2018

Pushed a version with a few more print statements.

@aharpervc
Copy link
Author

Debugging via github comments continues...

$ ruby .\test\tests.rb
Run options: --seed 32405

# Running:

....*** time seconds class Integer '1483660687'
*** time seconds class Integer '1483660687'
...........................................................................................................................................................*** test time: 2018-07-25 17:08:41 -0400
*** time seconds class Integer '1532552921'
{
  "^o":"Time",
  "time":1532552921.905583000
}
*** time seconds class Integer '1532552921'
{
  "^o":"Time",
  "time":1532552921.905583000e-14400
}
*** time seconds class Integer '1532552921'
{
  "^o":"Time",
  "time":"2018-07-25T17:08:41.905583000\u000045:04"
}
F

Failure:
CustomJuice#test_time [C:/Users/aharper/workspace/oj/test/test_custom.rb:351]:
--- expected
+++ actual
@@ -1,2 +1,2 @@
 # encoding: US-ASCII
-"2018-07-25 17:08:41 -0400"
+"2018-07-25 17:08:41 +0000"



bin/rails test C:/Users/aharper/workspace/oj/test/test_custom.rb:319

.....................................................................*** time seconds class Integer '1532552922'
..............................................*** time seconds class Integer '-2208987661'
E

Error:
Juice#test_time_neg:
RangeError: bignum too big to convert into `long'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `dump'
    C:/Users/aharper/workspace/oj/test/test_various.rb:412:in `test_time_neg'


bin/rails test C:/Users/aharper/workspace/oj/test/test_various.rb:410

.....................................................*** time seconds class Integer '1420493827'
.......*** time seconds class Integer '1420481527'
F

Failure:
ObjectJuice#test_ruby_time_12345 [C:/Users/aharper/workspace/oj/test/test_object.rb:522]:
Expected: 1420481527
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:513

.*** time seconds class Integer '1420522627'
F

Failure:
ObjectJuice#test_xml_time [C:/Users/aharper/workspace/oj/test/test_object.rb:468]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:460

............*** time seconds class Integer '1420493827'
...........*** time seconds class Integer '1420522627'
...........*** time seconds class Integer '1420493827'
......*** time seconds class Integer '1420522627'
F

Failure:
ObjectJuice#test_ruby_time [C:/Users/aharper/workspace/oj/test/test_object.rb:503]:
Expected: 1420522627
  Actual: 1420493827


bin/rails test C:/Users/aharper/workspace/oj/test/test_object.rb:495

..*** time seconds class Integer '1420481482'
....................................................................

Finished in 0.946108s, 475.6326 runs/s, 869.8792 assertions/s.
450 runs, 823 assertions, 4 failures, 1 errors, 0 skips

@ohler55
Copy link
Owner

ohler55 commented Jul 25, 2018

Ok, made some additional changes. Might have fixed some.

@aharpervc
Copy link
Author

Success!?

$ ruby .\test\tests.rb
Run options: --seed 23694

# Running:

................................................................................................................................................................................................................................................................................................................................................................*** test time: 2018-07-26 09:43:26 -0400
{
  "^o":"Time",
  "time":1532612606.440180000
}
{
  "^o":"Time",
  "time":1532612606.440180000e-14400
}
{
  "^o":"Time",
  "time":"2018-07-26T09:43:26.440180000-04:00"
}
*** ruby_time '2018-07-26 09:43:26 -0400' strlen: 25 rlen: 25
{
  "^o":"Time",
  "time":"2018-07-26 09:43:26 -0400"
}
..................................................................................................

Finished in 0.347786s, 1293.8984 runs/s, 2398.0250 assertions/s.
450 runs, 834 assertions, 0 failures, 0 errors, 0 skips

@ohler55
Copy link
Owner

ohler55 commented Jul 26, 2018

Better than I hoped for. Thanks. I'll clean up the debug stuff and make a release.

@aharpervc
Copy link
Author

I looked at the diff but it's over my head. What was the root cause? And were you able to determine why this was not discovered by existing tests or Windows CI?

@ohler55
Copy link
Owner

ohler55 commented Jul 26, 2018

There were two issues. One is that Windows thinks long integers are 32 bits when converting from Ruby but oddly not at other times. Using num2ll solved that. I tried a few approaches and finally zeroed in on that.

Second was a printf string with %ld was being given the wrong type so casting to a long fixed that.

@ohler55
Copy link
Owner

ohler55 commented Aug 14, 2018

Okay to close now that the release has been out for a few weeks?

@aharpervc
Copy link
Author

Okay to close now that the release has been out for a few weeks?

Fine by me, 3.6.5 seems to work fine and I'm sure I'll make a new issue if I find anything :D

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

No branches or pull requests

2 participants