You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
"io"
"log"
"net/http"
"time"
"github.com/norsegaud/go-daemon"
)
func main() {
daemonContext := &daemon.Context{
PidFileName: "test.pid",
PidFilePerm: 0644,
LogFileName: "test.log",
LogFilePerm: 0640,
WorkDir: "/tmp",
Umask: 027,
Args: []string{"SecPolicyCreateSSL"},
}
d, err := daemonContext.Reborn()
if err != nil {
log.Fatalln(err)
}
if d != nil { // return the parent process since it's now forked into a child
return
}
defer daemonContext.Release()
time.Sleep(5 * time.Second)
// go runService(serviceCtx)
fmt.Println("doing get...")
resp, err := http.Get("https://google.com")
if err != nil {
log.Println(err)
return
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Println(err)
return
}
fmt.Println(string(body))
return
err = daemon.ServeSignals()
if err != nil {
log.Printf("Error: %s", err.Error())
}
fmt.Println("main done")
}
run go run main.go and tail the test.log
cat test.log
doing get...
2024/07/22 14:22:24 Get "https://google.com": tls: failed to verify certificate: SecPolicyCreateSSL error: 0
If I remove the time.Sleep(5 * time.Second) from the main.go, it works. But that's because the child has access to things while the parent is still live. Once the parent has returned, the child gets the SSL error.
The child shouldn't be dependent on the parent, but I'm not entirely sure what to do about it.
The text was updated successfully, but these errors were encountered:
Reproduction on macOS:
clone go-daemon locally
create the files below and run
go mod tidy
go.mod
main.go
go run main.go
and tail the test.logIf I remove the
time.Sleep(5 * time.Second)
from the main.go, it works. But that's because the child has access to things while the parent is still live. Once the parent has returned, the child gets the SSL error.The child shouldn't be dependent on the parent, but I'm not entirely sure what to do about it.
The text was updated successfully, but these errors were encountered: