Skip to content

[bug] Added abs path ref. to devbox binary in wrappers #1260

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

Merged
merged 2 commits into from
Jul 10, 2023

Conversation

mohsenari
Copy link
Collaborator

Summary

This fixes an issue where if you install coreutils devbox shell in some cases gets stuck in infinite loop due this sequence of events:

  1. devbox shell creates wrappers
  2. wrappers try to omit wrappers from PATH and call devbox shellenv but it's unsuccessful
  3. devbox call in wrappers uses a couple of util tools (like tr) that now have their own wrappers because of coreutils.
  4. the process is never able to skip the wrappers hence showing fork: Resource Temporarily Unavailable

I think it addresses #881 or at least a portion of it.

The fix:
in step 3 instead of calling devbox (launcher script in /usr/local/bin) we get the absolute path to the devbox binary and reference that directly in wrappers script.
This way the launcher script is not called more than once and avoids getting stuck in infinite loop.

How was it tested?

  • compile -> compiled binary is now in /dist/devbox
  • update line 413 of launcher (/usr/local/devbox) to local -r bin="<path to devbox>/dist/devbox"
  • in an empty directory run devbox init
  • add coreutils@latest to devbox.json
  • run devbox shell

@mohsenari mohsenari requested review from gcurtis and mikeland73 July 7, 2023 22:49
@@ -29,6 +29,6 @@ should be in PATH.

DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
*/ -}}
eval "$(DO_NOT_TRACK=1 devbox shellenv only-path-without-wrappers)"
eval "$(DO_NOT_TRACK=1 {{ .DevboxBinaryPath }} shellenv only-path-without-wrappers)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eval "$(DO_NOT_TRACK=1 {{ .DevboxBinaryPath }} shellenv only-path-without-wrappers)"
eval "$(DO_NOT_TRACK=1 '{{ .DevboxBinaryPath }}' shellenv only-path-without-wrappers)"

@mohsenari mohsenari merged commit dea479d into main Jul 10, 2023
@mohsenari mohsenari deleted the mohsen--coreutils-loop-fix branch July 10, 2023 22:01
savil added a commit that referenced this pull request Jul 27, 2023
…se update notifications (#1324)

## Summary

**Motivation**

In #1260, the bin-wrappers were changed to invoke the devbox-binary,
instead of the devbox-launcher. However, when devbox has been updated,
these bin-wrappers have the older devbox-binary's path hardcoded. So,
they call the older devbox-binary leading to two issues:
1. runs older functionality of the older devbox binary
2. re-prints the notice about "New devbox available. Run .... to
update", despite the user already having updated their devbox.

**Implementation**

1. Create a symlink that always points to the "current" devbox binary. 
- I use "current" instead of "latest" to be consistent with the
Launcher's usage of these terms.
2. In the bin-wrappers, we prepend the directory containing this
devbox-symlink to PATH. The bin-wrappers revert back to directly
invoking devbox, as in `devbox shellenv`.
- This is done for robustness: if the symlink is missing, then the
bin-wrappers do still invoke `devbox` via the launcher. This is
problematic for users who have installed `coreutils` via devbox, but for
most users this fallback would work.
3. We ensure the bin-wrappers are created in
`ensurePackagesAreInstalled` that runs in `devbox.PrintEnv` during
`devbox shellenv`.
- This is needed because we need existing users that have the
bin-wrappers with the hardcoded DevboxExecutablePath to refresh their
bin-wrappers. When they open a new terminal, `devbox global shellenv`
would run, refreshing these bin-wrappers.
4. Finally, we create the Devbox symlink during `devbox version update`,
so that it points to the _new_ Devbox binary.
     

**Drawbacks**
Switching between devbox versions (for testing and development) may lead
to subtle unexpected behavior: The devbox-symlink will point to the
version that created the bin-wrappers, rather than respecting the devbox
of the PATH. We need to ensure we run `devbox install` or similar to
re-create the bin-wrappers.

## How was it tested?

1. Sanity check to do `devbox shell` in
`examples/development/go/hello-world`.
2. Sanity check to do `devbox run build` using the devbox binary from
this PR.
3. Deleted devbox-symlink, and ran `devbox version -v` to ensure that it
was re-created.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants