Skip to content

Commit 3a3b76c

Browse files
committed
fix: bug with global configuration
1 parent 6594ea5 commit 3a3b76c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

risefront.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
// Storing global configurations for use in Restart functions
2626
var (
27-
globalConfig Config
27+
globalConfig *Config
2828
)
2929

3030
// Dialer is used for the child-parent communication.
@@ -37,12 +37,12 @@ type Config struct {
3737
Addresses []string // Addresses to listen to.
3838
Run func([]net.Listener) error // Handle the connections. All open connections should be properly closed before returning (srv.Shutdown for http.Server for instance).
3939

40-
Name string // Name of the socket file
41-
Dialer Dialer // Dialer for child-parent communication. Let empty for default dialer (PrefixDialer{}).
42-
Network string // "tcp" (default if empty), "tcp4", "tcp6", "unix" or "unixpacket"
43-
ErrorHandler func(kind string, err error) // Where errors should be logged (print to stderr by default)
44-
RestartSignal os.Signal // Signal to trigger a restart
45-
NoRestart bool // Disables all restarts
40+
Name string // Name of the socket file
41+
Dialer Dialer // Dialer for child-parent communication. Let empty for default dialer (PrefixDialer{}).
42+
Network string // "tcp" (default if empty), "tcp4", "tcp6", "unix" or "unixpacket"
43+
ErrorHandler func(kind string, err error) // Where errors should be logged (print to stderr by default)
44+
RestartSignal os.Signal // Signal to trigger a restart
45+
NoRestart bool // Disables all restarts
4646
LogHandler func(loglevel LogLevel, kind string, args ...interface{}) // Where debug messages should be logged
4747

4848
_ struct{} // to later add fields without break compatibility.
@@ -59,12 +59,12 @@ type Config struct {
5959
// The parent will live as long as the context lives.
6060
// The child will live as long as the parent is alive and no other child has been started.
6161
func New(ctx context.Context, cfg Config) error {
62+
// Save the global configuration for use in Restart
63+
globalConfig = &cfg
64+
6265
// Save the original arguments to pass to the child process
6366
cfg.args = os.Args
6467

65-
// Save the global configuration for use in Restart
66-
globalConfig = cfg
67-
6868
// First, try to get file descriptors from overseer
6969
if listeners, err := FromOverseerFDs(); err != nil {
7070
return err
@@ -457,6 +457,10 @@ type childRequest struct {
457457

458458
// Restart creates a child process instead of sending a signal
459459
func Restart() {
460+
if globalConfig == nil {
461+
panic("globalConfig is nil, Restart() should only be called from within a child process")
462+
}
463+
460464
err := globalConfig.createChild()
461465
if err != nil {
462466
globalConfig.LogHandler(ErrorLevel, "restart.createChild", err)

0 commit comments

Comments
 (0)