Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix: address infinite hang when infisical run watch fails

Sheen Capadngan02dc23425c61
diff --git a/cli/packages/cmd/run.go b/cli/packages/cmd/run.go
index a232896f1e..7f11a3f95e 100644
--- a/cli/packages/cmd/run.go
+++ b/cli/packages/cmd/run.go
@@ -419,22 +419,23 @@ func executeCommandWithWatchMode(commandFlag string, args []string, watchModeInt
for {
<-recheckSecretsChannel
- watchMutex.Lock()
-
- newEnvironmentVariables, err := fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, token)
- if err != nil {
- log.Error().Err(err).Msg("[HOT RELOAD] Failed to fetch secrets")
- continue
- }
-
- if newEnvironmentVariables.ETag != currentETag {
- runCommandWithWatcher(newEnvironmentVariables)
- } else {
- log.Debug().Msg("[HOT RELOAD] No changes detected in secrets, not reloading process")
- }
+ func() {
+ watchMutex.Lock()
+ defer watchMutex.Unlock()
+
+ newEnvironmentVariables, err := fetchAndFormatSecretsForShell(request, projectConfigDir, secretOverriding, token)
+ if err != nil {
+ log.Error().Err(err).Msg("[HOT RELOAD] Failed to fetch secrets")
+ return
+ }
- watchMutex.Unlock()
+ if newEnvironmentVariables.ETag != currentETag {
+ runCommandWithWatcher(newEnvironmentVariables)
+ } else {
+ log.Debug().Msg("[HOT RELOAD] No changes detected in secrets, not reloading process")
+ }
+ }()
}
}