commercialhaskell / rio

A standard library for Haskell
Other
838 stars 54 forks source link

RIO.Process is running an "original" instead of a symbolic link #217

Closed k-bx closed 4 years ago

k-bx commented 4 years ago

I'm not fully sure what's happening here, the same codebase started behaving differently once I've reinstalled my Ubuntu from 18.04 to 20.04 but maybe that's unrelated.

I'm using RIO.Process to run my python subprocess. The python I'm trying to run is located in virtualenv:

$ ls -lah /home/kb/workspace/emotive_conjugations/venv/bin/python
lrwxrwxrwx 1 kb kb 16 Apr 25 23:23 /home/kb/workspace/emotive_conjugations/venv/bin/python -> /usr/bin/python3

Once I'm running that python, I get an error, because what it actually does is it ends up running /usr/bin/python3 instead, because it's calling the findExecutable to resolve the name internally:

λ RIO.Prelude.Simple.runSimpleApp (RIO.Process.findExecutable "/home/kb/workspace/emotive_conjugations/venv/bin/python")
Right "/usr/bin/python3.8"

So, my question is, who is wrong here and how should I call a virtualenv'ed python executable properly? Thanks!

snoyberg commented 4 years ago

What happens if you give it an absolute path in the first place?

k-bx commented 4 years ago

@snoyberg all right, I've created a minimal self-containing repo. I also confirm that the code works on macOS, but not Ubuntu 20.04, and suspect it might work fine on Ubuntu 18.04, which might be somewhat alarming https://github.com/k-bx/rio-process-symlink-issue

The README captures the build and run instructions

snoyberg commented 4 years ago

Does this reproduce with the process package?

k-bx commented 4 years ago

Yes, I rewrote it using the UnliftIO.Process and it works now

snoyberg commented 4 years ago

I'm quite confused about the claim that this works on macOS and Ubuntu 18.04 but not Ubuntu 20.04. I think I know what the problem is: usage of canonicalizePath instead of makeAbsolute in findExecutable. However, that functions behaves identically on macOS and Ubuntu 18.04: resolving symbolic links.

The repro you've provided isn't really minimal, since it depends on assumptions of virtualenv working identically across all OSes and versions. I'm fairly certain that's the problem here. My recommendation: can you try replacing canonicalizePath with makeAbsolute in the codebase and see if that solves the problem you're seeing?

snoyberg commented 4 years ago

I don't see a downside to the change, so I've opened #218.

k-bx commented 4 years ago

@snoyberg yes, tested with the patched rio, it works now. Thank you!