logging: fix race condition in startup
If a panic occurs in one of the workers, it can happen after the UI was initialised, but before the cleanup function has been registered. With this the start of the worker loops is deferred until the cleanup routine was registered. Signed-off-by: Moritz Poldrack <git@moritz.sh>
This commit is contained in:
parent
98c9d7bb78
commit
d66930749a
5
aerc.go
5
aerc.go
|
@ -166,11 +166,13 @@ func main() {
|
||||||
ui *libui.UI
|
ui *libui.UI
|
||||||
)
|
)
|
||||||
|
|
||||||
|
deferLoop := make(chan struct{})
|
||||||
|
|
||||||
aerc = widgets.NewAerc(conf, logger, func(cmd []string) error {
|
aerc = widgets.NewAerc(conf, logger, func(cmd []string) error {
|
||||||
return execCommand(aerc, ui, cmd)
|
return execCommand(aerc, ui, cmd)
|
||||||
}, func(cmd string) []string {
|
}, func(cmd string) []string {
|
||||||
return getCompletions(aerc, cmd)
|
return getCompletions(aerc, cmd)
|
||||||
}, &commands.CmdHistory)
|
}, &commands.CmdHistory, deferLoop)
|
||||||
|
|
||||||
ui, err = libui.Initialize(aerc)
|
ui, err = libui.Initialize(aerc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -180,6 +182,7 @@ func main() {
|
||||||
logging.UICleanup = func() {
|
logging.UICleanup = func() {
|
||||||
ui.Close()
|
ui.Close()
|
||||||
}
|
}
|
||||||
|
close(deferLoop)
|
||||||
|
|
||||||
if conf.Ui.MouseEnabled {
|
if conf.Ui.MouseEnabled {
|
||||||
ui.EnableMouse()
|
ui.EnableMouse()
|
||||||
|
|
|
@ -535,7 +535,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
|
||||||
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
|
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
|
||||||
|
|
||||||
view, err := NewAccountView(wizard.aerc, wizard.conf, &account,
|
view, err := NewAccountView(wizard.aerc, wizard.conf, &account,
|
||||||
wizard.aerc.logger, wizard.aerc)
|
wizard.aerc.logger, wizard.aerc, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
|
wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
|
||||||
account.Name)
|
account.Name)
|
||||||
|
|
|
@ -47,8 +47,8 @@ func (acct *AccountView) UiConfig() config.UIConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig,
|
func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountConfig,
|
||||||
logger *log.Logger, host TabHost) (*AccountView, error) {
|
logger *log.Logger, host TabHost, deferLoop chan struct{},
|
||||||
|
) (*AccountView, error) {
|
||||||
acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
|
acctUiConf := conf.GetUiConfig(map[config.ContextType]string{
|
||||||
config.UI_CONTEXT_ACCOUNT: acct.Name,
|
config.UI_CONTEXT_ACCOUNT: acct.Name,
|
||||||
})
|
})
|
||||||
|
@ -90,6 +90,10 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
|
||||||
go func() {
|
go func() {
|
||||||
defer logging.PanicHandler()
|
defer logging.PanicHandler()
|
||||||
|
|
||||||
|
if deferLoop != nil {
|
||||||
|
<-deferLoop
|
||||||
|
}
|
||||||
|
|
||||||
worker.Backend.Run()
|
worker.Backend.Run()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ type Choice struct {
|
||||||
|
|
||||||
func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
||||||
cmd func(cmd []string) error, complete func(cmd string) []string,
|
cmd func(cmd []string) error, complete func(cmd string) []string,
|
||||||
cmdHistory lib.History) *Aerc {
|
cmdHistory lib.History, deferLoop chan struct{},
|
||||||
|
) *Aerc {
|
||||||
tabs := ui.NewTabs(&conf.Ui)
|
tabs := ui.NewTabs(&conf.Ui)
|
||||||
|
|
||||||
statusbar := ui.NewStack(conf.Ui)
|
statusbar := ui.NewStack(conf.Ui)
|
||||||
|
@ -85,7 +85,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
||||||
conf.Triggers.ExecuteCommand = cmd
|
conf.Triggers.ExecuteCommand = cmd
|
||||||
|
|
||||||
for i, acct := range conf.Accounts {
|
for i, acct := range conf.Accounts {
|
||||||
view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc)
|
view, err := NewAccountView(aerc, conf, &conf.Accounts[i], logger, aerc, deferLoop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name)
|
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue