Skip to content

release lock on global process-compose before attaching #2645

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 1 commit into from
Jul 9, 2025

Conversation

jay-aye-see-kay
Copy link
Contributor

Summary

After running devbox services attach all other devbox services ... commands hang until the attached UI is exited. This is because there's a lock put on the global process-compose file while it's being read and it's not released until the program exits.

You can see in devbox services up the lockfile is released, looks like it was just missed in attach.

// We're waiting now, so we can unlock the file
config.File.Close()

How was it tested? (repro steps, hangs without this PR, works as expected with it)

In one terminal, in a devbox repo with process(es)

devbox services up -b
devbox services attach

In another terminal, in the same dir or any other devbox repo>

devbox services ls # or any services ... sub command
# will hang until <ctrl-c> in above terminal

Other note

The lock() function has a timeout and error handling, why doesn't it work?

func lockFile(file *os.File) error {
lockResult := make(chan error)
go func() {
err := syscall.Flock(int(file.Fd()), syscall.LOCK_EX)
lockResult <- err
}()
select {
case err := <-lockResult:
if err != nil {
file.Close()
return fmt.Errorf("failed to lock file: %w", err)
}
return nil
case <-time.After(fileLockTimeout):
file.Close()
return fmt.Errorf("process-compose file lock timed out after %d seconds", fileLockTimeout/time.Second)
}
}

The line that hangs is 391, when we're trying to close the file after the timeout, the file can't be closed because another process has it open and/or locked. I did investigate adding a timeout file.Close() but could not get it to work reliably for myself.

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

@jay-aye-see-kay
Copy link
Contributor Author

Demo of the issue

OUTPUT_SCALED.mp4

@Lagoja Lagoja requested review from Lagoja and mikeland73 July 9, 2025 02:18
@Lagoja
Copy link
Contributor

Lagoja commented Jul 9, 2025

Thanks for attaching the video demo as well!

@Lagoja Lagoja merged commit 72d01ea into jetify-com:main Jul 9, 2025
30 checks passed
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