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

fnm current version reset on sleep / lock / stale terminal #624

Closed
uloco opened this issue Jan 5, 2022 · 29 comments · Fixed by #626 or #638
Closed

fnm current version reset on sleep / lock / stale terminal #624

uloco opened this issue Jan 5, 2022 · 29 comments · Fixed by #626 or #638

Comments

@uloco
Copy link

uloco commented Jan 5, 2022

Since I installed the latest fnm to try the new recursive version strategy I have the following problem:

When I lock my mac and put it into sleep for some time, my current shell sessions (including vscode) cannot find node & npx anymore. I think the symlink is getting cleaned up or something? When I open up a new terminal fnm is working properly again. But the current shell does not have any current node version. fnm current outputs none.

My setup is as simple as the following as first line in .zshrc:

eval "$(fnm env --use-on-cd --version-file-strategy recursive)"
@uloco
Copy link
Author

uloco commented Jan 5, 2022

To be clear, I am not quite sure if it only happens when on sleep / lock. It may also have happened randomly in terminal sessions, that I haven't used for some time. Can this happen at all?

@uloco
Copy link
Author

uloco commented Jan 5, 2022

Ok, seems like it is not related to sleep / lock only. I did not use the terminal for a while, since I was debugging something and then tried to commit something and husky could not find node in that terminal. There is something cleaned up underneath for sure after some time.

@uloco
Copy link
Author

uloco commented Jan 5, 2022

If I try to run fnm use afterwards, this error is thrown

❯ fnm use
Using Node v16.13.0
error: Can't create the symlink: No such file or directory (os error 2)

@uloco uloco changed the title fnm current version reset on sleep / lock fnm current version reset on sleep / lock / stale terminal Jan 5, 2022
@Schniz
Copy link
Owner

Schniz commented Jan 5, 2022

Seems like your test directory is being deleted every couple of minutes. What OS are you using?

@Schniz
Copy link
Owner

Schniz commented Jan 5, 2022

the following PR should fix the Can't create the symlink issue, but not the staleness after the deletion of the symlink:

#626

@alexeyten
Copy link
Contributor

alexeyten commented Jan 5, 2022

What OS are you using?

When I lock my mac

I guess it's MacOS 😅

@Schniz
Copy link
Owner

Schniz commented Jan 5, 2022

Then maybe you’re low on storage? 😳

@uloco
Copy link
Author

uloco commented Jan 6, 2022

No I have 500GB space left ...

@uloco
Copy link
Author

uloco commented Jan 6, 2022

I am on latest macos running iterm2 and zsh. This issue did not ever happen before with fnm, just started after i updated to the latest fnm version. I was on 1.28.x before...

@uloco
Copy link
Author

uloco commented Jan 6, 2022

I will try the fix for now thank you

@uloco
Copy link
Author

uloco commented Jan 10, 2022

The last release did not fix this issue @Schniz. Do you have any idea to investigate more what is happening? Is there any way for me to install a 1.28.x version on mac and test if it is still happening? Did you introduce any changes since then, that could have caused this issue?

@Schniz
Copy link
Owner

Schniz commented Jan 10, 2022

Let's try: you can download any release from the releases page. Download the version that matches your OS and arch, and chmod u+x it and let me know if that fixes the issue!

The release shouldn't have been fixed it, just make the cryptic error disappear. The issue is temp directory being cleaned when the computer sleeps which never happened to me

@uloco
Copy link
Author

uloco commented Jan 10, 2022

@Schniz It is happening without sleep. I noticed it happens randomly all the time. I have no clue what is happening. I first thought it's when I open a new terminal or vscode but it is not reproducable. :(

@uloco
Copy link
Author

uloco commented Jan 10, 2022

@Schniz Since I am using 1.28.2 it works. There is no problem anymore. It has to do something with the recent changes about recursive strategy I guess ....

@Schniz
Copy link
Owner

Schniz commented Jan 10, 2022

this is very weird. again, never had these problems. based on #624 (comment) what I believe is that it fails in

replace_symlink(&version_path, multishell_path).context(SymlinkingCreationIssue)?;

and since the error is No such file or directory, all that left to assume is that it is related to tmp dir that being cleaned up.

We can test it though, if you use 1.29.2 :) like:

  • use latest fnm
  • wait for this to happen again...
  • what does this print? echo $FNM_MULTISHELL_PATH; ls $FNM_MULTISHELL_PATH
  • then, what does this print? ls $(dirname $FNM_MULTISHELL_PATH)
  • then, what does this print? ls $(dirname $FNM_MULTISHELL_PATH)/..

I don't find anything weird in the changes between 1.28.2 and 1.29.1 🤔

@uloco
Copy link
Author

uloco commented Jan 10, 2022

@Schniz fyi this is the output in a working directory

❯ echo $FNM_MULTISHELL_PATH; ls $FNM_MULTISHELL_PATH
/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/48743_1641831655676
/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/48743_1641831655676@

❯ ls $(dirname $FNM_MULTISHELL_PATH)
22206_1641823794807@  23184_1641824249661@  23630_1641824287347@  25606_1641825312240@  26613_1641825753935@  28107_1641826628256@  40728_1641828773601@  48442_1641831560096@  48922_1641831662934@
22325_1641823854935@  23271_1641824265847@  25291_1641825230481@  25686_1641825312544@  26711_1641825761566@  28476_1641826862874@  41871_1641829045298@  48552_1641831591625@  49041_1641831670335@
22416_1641823864535@  23359_1641824275850@  25404_1641825307771@  25743_1641825312636@  27095_1641826015774@  33417_1641827871486@  46485_1641830384450@  48643_1641831605041@  49094_1641831670544@
22827_1641824185566@  23447_1641824278388@  25489_1641825311858@  25913_1641825322913@  27256_1641826067770@  3482_1641813495699@   47645_1641830753631@  48743_1641831655676@  5805_1641813562040@
22969_1641824199622@  23538_1641824281420@  25532_1641825312061@  26105_1641825422833@  27911_1641826558301@  40432_1641828750668@  48335_1641831517257@  48836_1641831661843@

❯ ls $(dirname $FNM_MULTISHELL_PATH/..)
/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/48743_1641831655676@

@Schniz
Copy link
Owner

Schniz commented Jan 10, 2022

Can you investigate it a bit? Seems like the symlink is broken? Can you ls -l it so we can see what is it linking to?

@uloco
Copy link
Author

uloco commented Jan 11, 2022

I'm using the latest now and cannot reproduce anymore since I restarted my mac yesterday. This is sooo weird. Hopefully it is magically resolved now. Will keep you updated. Thanks :)

@Schniz
Copy link
Owner

Schniz commented Jan 11, 2022

😱

thank you!

@uloco
Copy link
Author

uloco commented Jan 12, 2022

Unfortunately it started happening again.

❯ echo $FNM_MULTISHELL_PATH; ls $FNM_MULTISHELL_PATH
/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/73533_1641984154584
gls: cannot access '/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/73533_1641984154584': No such file or directory

❯ ls $(dirname $FNM_MULTISHELL_PATH)
gls: cannot access '/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells': No such file or directory

❯ ls $(dirname $FNM_MULTISHELL_PATH/..)
gls: cannot access '/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/73533_1641984154584': No such file or directory

I did a small break for 20 minutes and when I came back to my desk, node was no longer available.

❯ fnm env
export PATH="/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/80048_1641986722987/bin":$PATH
export FNM_MULTISHELL_PATH="/var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells/80048_1641986722987"
export FNM_VERSION_FILE_STRATEGY="recursive"
export FNM_DIR="/Users/uloco/.fnm"
export FNM_LOGLEVEL="info"
export FNM_NODE_DIST_MIRROR="https://nodejs.org/dist"
export FNM_ARCH="arm64"
rehash

The default alias is still present though

❯ ll -l /var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/fnm_multishells
total 0
lrwxr-xr-x 1 uloco staff 33 Jan 12 12:25 80048_1641986722987 -> /Users/uloco/.fnm/aliases/default/

❯ fnm ls
* v11.15.0
* v12.13.0
* v12.14.1
* v14.17.5
* v15.6.0
* v16.13.0 default, lts-latest
* system

@uloco
Copy link
Author

uloco commented Jan 12, 2022

@Schniz Is there a way to change / configure the paths for the symlinks?

@alexeyten
Copy link
Contributor

alexeyten commented Jan 12, 2022

@ulco, It's undocumented, but you could set TMPDIR environment variable.
Actually, I use this snippet in my .bashrc

mkdir -p $HOME/.tmp
. <(TMPDIR=$HOME/.tmp fnm env)

and the result is:

~ $ echo $FNM_MULTISHELL_PATH 
/home/[edited]/.tmp/fnm_multishells/973909_1641984228694

@uloco
Copy link
Author

uloco commented Jan 12, 2022

Thanks @alexeyten.

I think what I did add after it worked for some time is the flag with recursive again. I had deleted it in the meantime to try out if it was the issue and I think it is causing it.
Because $TMPDIR is set to /var/folders/j5/ckgkc5b95wb6p5vhwt_h9dyr0000gn/T/by default and it is still present and full of other stuff besides fnm. only the fnm_multishell folder is cleaned up, and also only the node_versions thing.

I don't have a .node_version file in my $HOME, maybe this is causing it somehow also.

@uloco
Copy link
Author

uloco commented Jan 12, 2022

I am removing the --version-file-strategy flag now to see if it happens again.

@uloco
Copy link
Author

uloco commented Jan 12, 2022

FYI, removing the flag did not solve it!
Now trying with changing $TMPDIR.

@uloco
Copy link
Author

uloco commented Jan 12, 2022

Changing $TMPDIR like @alexeyten suggested works so far.

@Schniz
Copy link
Owner

Schniz commented Jan 13, 2022

Happy to announce that I am now running Monterey 12.1 and it happens to me too 😭

@Schniz Schniz reopened this Jan 13, 2022
@alexeyten
Copy link
Contributor

Probably you should not use TMP for this.
For XDG I would like to use $XDG_STATE_HOME or $XDG_RUNTIME_DIR. Not sure what are appropriate analog for them in MacOS.

@uloco
Copy link
Author

uloco commented Jan 13, 2022

I found some info about /var/folders and why it is not a good place in general.
https://magnusviri.com/what-is-var-folders.html

Also /tmp is periodically cleaned up by /etc/periodic/{daily,monthyl,weekly} which is maybe better? but it has drwxrwxrwt

The local standard cache dir is ~/Library/Caches for macos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants