Skip to content

Commit 92bb293

Browse files
authored
[shellenv] Fix infinite loop (#1083)
## Summary Fixes #1049 In certain cases, shellenv might call a wrapped binary causing an infinite loop. This prevents it. ## How was it tested? Called a test script and confirmed env var was set.
1 parent e2c134d commit 92bb293

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/wrapnix/wrapper.sh.tmpl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ fi
1414
{{- end }}
1515

1616
{{/*
17-
We use ShellEnvHashKey to avoid re-sourcing shellenv. Since wrappers
18-
call other wrappers and potentially modify the environment, we don't want the
19-
environment to get re-written.
17+
We use ShellEnvHashKey to prevent doing shellenv if the correct environment is
18+
already set. (perf optimization)
19+
20+
We use the guard to prevent infinite loop if something in shellenv causes
21+
another wrapped binary to be called. The guard is specific to this project so shellenv
22+
could still cause another project's shellenv to be called.
2023

2124
DO_NOT_TRACK=1 can be removed once we optimize segment to queue events.
2225
*/ -}}
2326

24-
if [[ "${{ .ShellEnvHashKey }}" != "{{ .ShellEnvHash }}" ]]; then
27+
if [[ "${{ .ShellEnvHashKey }}" != "{{ .ShellEnvHash }}" ]] && [[ -z "${{ .ShellEnvHashKey }}_GUARD" ]]; then
28+
export {{ .ShellEnvHashKey }}_GUARD=true
2529
eval "$(DO_NOT_TRACK=1 devbox shellenv -c {{ .ProjectDir }})"
2630
fi
2731

0 commit comments

Comments
 (0)