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

Dir.chdir and native functions #5743

ahorek opened this issue May 22, 2019 · 2 comments


None yet
2 participants
Copy link

commented May 22, 2019


jruby (2.5.3) 2019-05-18 d79edcd Java HotSpot(TM) 64-Bit Server VM 11.0.2+9-LTS on 11.0.2+9-LTS +jit [linux-x86_64]

link with sass/sassc-ruby#119

Expected Behavior

here's a pseudo code to describe the issue

C++ (

std::string get_cwd() (
  const size_t wd_len = 4096;
  char wd[wd_len];
  char* cwd = getcwd(wd, wd_len);
  return cwd;


Dir.chdir('/tmp') do
  CALL_FUNCTION(get_cwd) # ffi

on jruby, the current directory remains unchanged, Dir.chdir has no effect

Actual Behavior

It probably won't be easy to fix, see #5145 and others


This comment has been minimized.

Copy link

commented May 28, 2019

This is intentional; Dir.chdir is not thread-safe at the native level, and since JRuby is often hosted alongside other applications on the JVM, it would not be appropriate for us to start changing the process's current directory.

However... I recognize that the majority of JRuby users these days run a single JRuby in a single JVM, in which case Dir.chdir could possibly do the real native call and change the process's current directory, even though this is still poorly specified across threads.

We also have a mechanism to detect when JRuby is the "main" for this JVM, in which case making chdir do the native behavior might be fine.

@enebo thoughts?


This comment has been minimized.

Copy link
Contributor Author

commented May 28, 2019

thanks @headius , that's what I thought

It does affect sassc-ruby test suite, but the gem usually works fine. so it's not a big deal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.