Skip to content

Commit

Permalink
fix #258: Prevent PC stuck in down command with daemon Launching scen…
Browse files Browse the repository at this point in the history
…ario
  • Loading branch information
F1bonacc1 committed Oct 26, 2024
1 parent b0d388b commit 2f0dfb9
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 3 deletions.
20 changes: 20 additions & 0 deletions issues/issue_258/devbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.13.0/.schema/devbox.schema.json",
"packages": {
"postgresql":"latest",
"glibcLocales": {
"version": "latest",
"platforms": ["x86_64-linux", "aarch64-linux"]
}
},
"shell": {
"init_hook": [
"echo 'Welcome to devbox!' > /dev/null"
],
"scripts": {
"test": [
"echo \"Error: no test specified\" && exit 1"
]
}
}
}
158 changes: 158 additions & 0 deletions issues/issue_258/devbox.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"lockfile_version": "1",
"packages": {
"glibcLocales@latest": {
"last_modified": "2024-10-13T23:44:06Z",
"resolved": "github:NixOS/nixpkgs/d4f247e89f6e10120f911e2e2d2254a050d0f732#glibcLocales",
"source": "devbox-search",
"version": "2.40-36",
"systems": {
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/nscqaw8kyv5470vspm7zjacc5vmpa1mq-glibc-locales-2.40-36",
"default": true
}
],
"store_path": "/nix/store/nscqaw8kyv5470vspm7zjacc5vmpa1mq-glibc-locales-2.40-36"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/px8cvmxycca75kfbk5w4anlnqkbip773-glibc-locales-2.40-36",
"default": true
}
],
"store_path": "/nix/store/px8cvmxycca75kfbk5w4anlnqkbip773-glibc-locales-2.40-36"
}
}
},
"postgresql@latest": {
"last_modified": "2024-10-18T15:35:18Z",
"plugin_version": "0.0.2",
"resolved": "github:NixOS/nixpkgs/ccc0c2126893dd20963580b6478d1a10a4512185#postgresql",
"source": "devbox-search",
"version": "16.4",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/6dzxj78wph840cpwslh96s4gpm0iwch2-postgresql-16.4",
"default": true
},
{
"name": "man",
"path": "/nix/store/z1n2vh799a5icpaxbrjfqsasagb276bk-postgresql-16.4-man",
"default": true
},
{
"name": "dev",
"path": "/nix/store/afjpl8ilq8s6j6zh4qqyy6mxz3v2xbav-postgresql-16.4-dev"
},
{
"name": "doc",
"path": "/nix/store/ry9d9by692xj92y5b9j6z0aa5y3lh3px-postgresql-16.4-doc"
},
{
"name": "lib",
"path": "/nix/store/d1im42w02x8gl2y380r4hgj8xgkkkbwc-postgresql-16.4-lib"
}
],
"store_path": "/nix/store/6dzxj78wph840cpwslh96s4gpm0iwch2-postgresql-16.4"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/37r0vmsb8xd1kv3wjd99kr59q99ja3g0-postgresql-16.4",
"default": true
},
{
"name": "man",
"path": "/nix/store/mawnv85hv5y64csbmpgrnz88j7r8cby5-postgresql-16.4-man",
"default": true
},
{
"name": "dev",
"path": "/nix/store/ibhwvhq4gkdibkfrkqg9vmip9mhhrg2q-postgresql-16.4-dev"
},
{
"name": "doc",
"path": "/nix/store/rmvkab0pxjjjznk350syr3gzpa13dz1k-postgresql-16.4-doc"
},
{
"name": "lib",
"path": "/nix/store/39mnmp40qhpq2h6r3cj66s23sb5fkzr6-postgresql-16.4-lib"
},
{
"name": "debug",
"path": "/nix/store/71hz4hv1n6ivymbzd0jm3a61cyj9fwh5-postgresql-16.4-debug"
}
],
"store_path": "/nix/store/37r0vmsb8xd1kv3wjd99kr59q99ja3g0-postgresql-16.4"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/vlgydd1rakmw9j14i8dgrlhzj4pa82vi-postgresql-16.4",
"default": true
},
{
"name": "man",
"path": "/nix/store/2wm2caki07a557z97228n2zxrd3a8j4b-postgresql-16.4-man",
"default": true
},
{
"name": "dev",
"path": "/nix/store/96nxx00m06jl2jmvb16916l2rpwb13hk-postgresql-16.4-dev"
},
{
"name": "doc",
"path": "/nix/store/r03r96a44grl85sflw6hvwwlrzr32rk9-postgresql-16.4-doc"
},
{
"name": "lib",
"path": "/nix/store/cy3q9y20jwk1vkd6jxf3mnq6xzbb9dn8-postgresql-16.4-lib"
}
],
"store_path": "/nix/store/vlgydd1rakmw9j14i8dgrlhzj4pa82vi-postgresql-16.4"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/mjjfx6yyaaba5hmv6bga20m8fxrca93l-postgresql-16.4",
"default": true
},
{
"name": "man",
"path": "/nix/store/b8cvsw47h2487y4j805zi0645x3ajh1i-postgresql-16.4-man",
"default": true
},
{
"name": "dev",
"path": "/nix/store/pqya8lq5jyplfmbmafrrwsrsi07d5ssn-postgresql-16.4-dev"
},
{
"name": "doc",
"path": "/nix/store/apbxfs52v8im9725mn2f1jhgbdfggrpd-postgresql-16.4-doc"
},
{
"name": "lib",
"path": "/nix/store/32cprs7xwxvb0rw2imfrgy5vcacc27hc-postgresql-16.4-lib"
},
{
"name": "debug",
"path": "/nix/store/alcnsd7fkkr3iipvcn9gzsyv16kab6m9-postgresql-16.4-debug"
}
],
"store_path": "/nix/store/mjjfx6yyaaba5hmv6bga20m8fxrca93l-postgresql-16.4"
}
}
}
}
}
21 changes: 21 additions & 0 deletions issues/issue_258/process-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "0.5"
log_level: debug
log_length: 3000
is_strict: true
disable_env_expansion: true

processes:
postgresql:
command: "exec pg_ctl start -o \"-k /home/eugene/projects/go/process-compose/issues/issue_258/.devbox/virtenv/postgresql\" && wait"
is_daemon: true
shutdown:
command: "pg_ctl stop -m fast"
availability:
restart: "always"
readiness_probe:
exec:
command: "pg_isready"
pc_log:
command: "tail -f -n100 process-compose-${USER}.log"
working_dir: "/tmp"
environment:
23 changes: 20 additions & 3 deletions src/app/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,29 @@ func (p *Process) run() int {
}

func (p *Process) waitForStdOutErr() {
ctx, cancel := context.WithCancel(context.Background())
if p.procConf.IsDaemon {
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
}
defer cancel()
if p.stdOutDone != nil {
<-p.stdOutDone
select {
case <-ctx.Done():
log.Debug().Msgf("%s stdout done with timeout", p.getName())
return
case <-p.stdOutDone:
log.Debug().Msgf("%s stdout done", p.getName())
}
p.stdOutDone = nil
}
if p.stdErrDone != nil {
<-p.stdErrDone
select {
case <-ctx.Done():
log.Debug().Msgf("%s stderr done with timeout", p.getName())
return
case <-p.stdErrDone:
log.Debug().Msgf("%s stderr done", p.getName())
}
p.stdErrDone = nil
}
}
Expand Down Expand Up @@ -424,7 +441,7 @@ func (p *Process) doConfiguredStop(params types.ShutDownParams) error {
}

func (p *Process) isRunning() bool {
return p.isOneOfStates(types.ProcessStateRunning, types.ProcessStateLaunched)
return p.isOneOfStates(types.ProcessStateRunning, types.ProcessStateLaunched, types.ProcessStateLaunching)
}

func (p *Process) prepareForShutDown() {
Expand Down

0 comments on commit 2f0dfb9

Please sign in to comment.