Fix race condition when setting app name in console output

This commit is contained in:
Dane Everitt 2021-08-15 16:46:55 -07:00
parent a2a02906ea
commit f7c8571f46

View File

@ -19,6 +19,8 @@ import (
// a server. // a server.
var appName string var appName string
var appNameSync sync.Once
var ErrTooMuchConsoleData = errors.New("console is outputting too much data") var ErrTooMuchConsoleData = errors.New("console is outputting too much data")
type ConsoleThrottler struct { type ConsoleThrottler struct {
@ -131,9 +133,9 @@ func (s *Server) Throttler() *ConsoleThrottler {
// PublishConsoleOutputFromDaemon sends output to the server console formatted // PublishConsoleOutputFromDaemon sends output to the server console formatted
// to appear correctly as being sent from Wings. // to appear correctly as being sent from Wings.
func (s *Server) PublishConsoleOutputFromDaemon(data string) { func (s *Server) PublishConsoleOutputFromDaemon(data string) {
if appName == "" { appNameSync.Do(func() {
appName = config.Get().AppName appName = config.Get().AppName
} })
s.Events().Publish( s.Events().Publish(
ConsoleOutputEvent, ConsoleOutputEvent,
colorstring.Color(fmt.Sprintf("[yellow][bold][%s Daemon]:[default] %s", appName, data)), colorstring.Color(fmt.Sprintf("[yellow][bold][%s Daemon]:[default] %s", appName, data)),