We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Almalinux 9, x86_64 on Virtuozzo 7 virtualization.
go-daemon v0.1.6
go 1.19.2
Method Context.parent() in daemon_unix.go contains the following code:
Context.parent()
daemon_unix.go
encoder := json.NewEncoder(d.wpipe) if err = encoder.Encode(d); err != nil { return } _, err = fmt.Fprint(d.wpipe, "\n\n")
In some cases the following happens:
encoder.Encode(d)
decoder.Decode(d)
fmt.Fprint(d.wpipe, "\n\n")
As a result Context.Reborn() fails with write |1: broken pipe though the child process is successfully started.
Context.Reborn()
write |1: broken pipe
In some cases Context.Reborn() can fail with write |1: broken pipe though the child process is successfully started.
Compile and run the following program on Almalinux 9 x86_64, Virtuozzo 7:
package main import ( "log" daemon "github.com/avoronkov/go-daemon" ) func main() { cntxt := &daemon.Context{ LogFileName: "sample.log", LogFilePerm: 0640, } d, err := cntxt.Reborn() if err != nil { log.Fatal("Unable to run: ", err) } if d != nil { // Parent process log.Printf("Parent: OK") return } defer cntxt.Release() log.Print("Child: OK") }
The program fails with the following error:
$ ./prog 2022/10/17 20:29:30 Unable to run: write |1: broken pipe
Program finishes successfully.
Parent writes message Parent: OK
Parent: OK
Child writes message Child: OK into "sample.log"
Child: OK
The problem was found when I tried to run existing application which uses go-daemon on Almalinux 9 (which is quite new RedHat-based OS).
go-daemon
Apply the following patch:
--- a/daemon_unix.go +++ b/daemon_unix.go @@ -113,7 +113,6 @@ func (d *Context) parent() (child *os.Process, err error) { if err = encoder.Encode(d); err != nil { return } - _, err = fmt.Fprint(d.wpipe, "\n\n") return }
Looks like writing "\n\n" into a pipe after encoding json is redundant. At least I was not able to find the problem it fixes.
"\n\n"
The text was updated successfully, but these errors were encountered:
fix race condition on writing in wpipe (write |1: broken pipe) (sevly…
8176800
…ar#86)
Merge pull request #87 from avoronkov/master
f0627db
fix race condition on writing in wpipe (write |1: broken pipe) (#86)
No branches or pull requests
Platform, version
Almalinux 9, x86_64 on Virtuozzo 7 virtualization.
go-daemon v0.1.6
go 1.19.2
Problem statement
Method
Context.parent()
indaemon_unix.go
contains the following code:In some cases the following happens:
encoder.Encode(d)
;decoder.Decode(d)
;fmt.Fprint(d.wpipe, "\n\n")
.As a result
Context.Reborn()
fails withwrite |1: broken pipe
though the child process is successfully started.Impact
In some cases
Context.Reborn()
can fail withwrite |1: broken pipe
though the child process is successfully started.Steps to reproduce
Compile and run the following program on Almalinux 9 x86_64, Virtuozzo 7:
Actual result
The program fails with the following error:
Expected result
Program finishes successfully.
Parent writes message
Parent: OK
Child writes message
Child: OK
into "sample.log"Additional information
The problem was found when I tried to run existing application which uses
go-daemon
on Almalinux 9 (which is quite new RedHat-based OS).Possible fix
Apply the following patch:
Looks like writing
"\n\n"
into a pipe after encoding json is redundant.At least I was not able to find the problem it fixes.
The text was updated successfully, but these errors were encountered: