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
4 changed files with 14 additions and 7 deletions
5
aerc.go
5
aerc.go
|
@ -166,11 +166,13 @@ func main() {
|
|||
ui *libui.UI
|
||||
)
|
||||
|
||||
deferLoop := make(chan struct{})
|
||||
|
||||
aerc = widgets.NewAerc(conf, logger, func(cmd []string) error {
|
||||
return execCommand(aerc, ui, cmd)
|
||||
}, func(cmd string) []string {
|
||||
return getCompletions(aerc, cmd)
|
||||
}, &commands.CmdHistory)
|
||||
}, &commands.CmdHistory, deferLoop)
|
||||
|
||||
ui, err = libui.Initialize(aerc)
|
||||
if err != nil {
|
||||
|
@ -180,6 +182,7 @@ func main() {
|
|||
logging.UICleanup = func() {
|
||||
ui.Close()
|
||||
}
|
||||
close(deferLoop)
|
||||
|
||||
if conf.Ui.MouseEnabled {
|
||||
ui.EnableMouse()
|
||||
|
|
|
@ -535,7 +535,7 @@ func (wizard *AccountWizard) finish(tutorial bool) {
|
|||
wizard.conf.Accounts = append(wizard.conf.Accounts, account)
|
||||
|
||||
view, err := NewAccountView(wizard.aerc, wizard.conf, &account,
|
||||
wizard.aerc.logger, wizard.aerc)
|
||||
wizard.aerc.logger, wizard.aerc, nil)
|
||||
if err != nil {
|
||||
wizard.aerc.NewTab(errorScreen(err.Error(), wizard.conf.Ui),
|
||||
account.Name)
|
||||
|
|
|
@ -47,8 +47,8 @@ func (acct *AccountView) UiConfig() config.UIConfig {
|
|||
}
|
||||
|
||||
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{
|
||||
config.UI_CONTEXT_ACCOUNT: acct.Name,
|
||||
})
|
||||
|
@ -90,6 +90,10 @@ func NewAccountView(aerc *Aerc, conf *config.AercConfig, acct *config.AccountCon
|
|||
go func() {
|
||||
defer logging.PanicHandler()
|
||||
|
||||
if deferLoop != nil {
|
||||
<-deferLoop
|
||||
}
|
||||
|
||||
worker.Backend.Run()
|
||||
}()
|
||||
|
||||
|
|
|
@ -48,8 +48,8 @@ type Choice struct {
|
|||
|
||||
func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
||||
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)
|
||||
|
||||
statusbar := ui.NewStack(conf.Ui)
|
||||
|
@ -85,7 +85,7 @@ func NewAerc(conf *config.AercConfig, logger *log.Logger,
|
|||
conf.Triggers.ExecuteCommand = cmd
|
||||
|
||||
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 {
|
||||
tabs.Add(errorScreen(err.Error(), conf.Ui), acct.Name)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue