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

File.utime failing with Errno::EINVAL on JRuby 9.1.17.0 #5261

Closed
danielford opened this issue Jul 25, 2018 · 4 comments
Closed

File.utime failing with Errno::EINVAL on JRuby 9.1.17.0 #5261

danielford opened this issue Jul 25, 2018 · 4 comments

Comments

@danielford
Copy link

danielford commented Jul 25, 2018

Environment

  • JRuby version: 9.1.17.0
  • OS/platform: 4.4.20-0.1.fm.237.49.326.metal1.x86_64 #1 SMP Wed Sep 21 11:35:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
  • Running inside a Docker container

Expected Behavior

This should succeed:

now = Time.now
File.utime(now, now, "foo.txt")

Actual Behavior

This used to work in 9.1.15.0, but now that we've upgraded to 9.1.17.0 we are getting the following error:

Errno::EINVAL: Invalid argument - Invalid argument
org/jruby/RubyFile.java:1177:in `utime' 

Investigation

I tried to troubleshoot this a bit, and I believe I know what's happening. I believe this is related to the patch that was added in #5075. I'm pretty sure what's happening is that the call to utimensat(...) here is failing with a NotImplementedError as described in #5075, and then it is falling back to calling utimes in the catch block here. However, that line is passing in the same exact atimespec and mtimespec values from the first call and those values are basically a two-element array containing [seconds, nanoseconds], but utimes is expecting [seconds, microseconds]. Thus, it fails with an Errno::EINVAL: Invalid argument - Invalid argument whenever the nanoseconds value is >= 1,000,000 (which would be an invalid value for microseconds). I'm guessing whoever tested the patch from #5075 must be running on a platform where utimes is more tolerant of invalid microsecond values.

To validate this, I ran the above code in a loop 100,000 times and it actually succeeded 134 times (0.134%). You'd expect the nanoseconds value to be < 1,000,000 about 0.1% of the time. I also ran against 9.1.16.0 and got the same exact NotImplementedError: utimensat unsupported or native support failed to load error referenced in #5075.

It seems like a pretty simple fix to just divide the nanoseconds value by 1,000 inside the catch block before the call to utimes. I will follow up later with a pull request to fix, but that will take me some more time to build and test. I wanted to submit the issue now in case anyone else is having the same problem, and to get any feedback on if my investigation and proposed fix makes sense.

I should also mention that despite the title, I'm assuming this is still an issue with JRuby 9.2.0.0 since the relevant code hasn't changed (we just haven't had a chance to upgrade to 9.2.0.0 yet)

@headius
Copy link
Member

headius commented Aug 16, 2018

@danielford Good investigation, thank you. I'll have a look at your PR.

headius added a commit that referenced this issue Aug 16, 2018
Fix parameters to utimes() fallback call (fixes #5261)
@headius
Copy link
Member

headius commented Aug 16, 2018

Thanks for the fix! I'm not sure we're planning to release a 9.1.18 now that the 9.2 line has become well-established, but we'll fix those milestones when we do release (cc @enebo).

@headius headius added this to the JRuby 9.1.18.0 milestone Aug 16, 2018
@headius
Copy link
Member

headius commented Aug 16, 2018

I just realized this was a PR against master, which is now the 9.2 line. I'll cherry-pick this change over to the jruby-9.1 branch as well.

@danielford
Copy link
Author

Thanks for merging!

I will say that if there is still a chance you folks would release 9.1.18.0, we'd appreciate it. We have started working on importing 9.2 into my company's custom build/deploy system but there were enough changes that it wasn't as easy as dropping in a new tarball (as it would be for the 9.1 branch). But of course we will understand either way, we appreciate the work that goes into creating and supporting JRuby!

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