Fix deadlock
This commit is contained in:
rodič
de4e7a1c4c
revize
1f484d20c7
16
msgbus.go
16
msgbus.go
|
@ -334,7 +334,7 @@ func (mb *MessageBus) readLog(f fs.FileInfo) error {
|
|||
return fmt.Errorf("error opening log %s: %w", f, err)
|
||||
}
|
||||
|
||||
t := mb.NewTopic(filepath.Base(f.Name()))
|
||||
t := mb.newTopic(filepath.Base(f.Name()))
|
||||
t.Created = f.ModTime()
|
||||
|
||||
index, err := l.LastIndex()
|
||||
|
@ -399,11 +399,7 @@ func (mb *MessageBus) Metrics() *Metrics {
|
|||
return mb.metrics
|
||||
}
|
||||
|
||||
// NewTopic ...
|
||||
func (mb *MessageBus) NewTopic(topic string) *Topic {
|
||||
mb.Lock()
|
||||
defer mb.Unlock()
|
||||
|
||||
func (mb *MessageBus) newTopic(topic string) *Topic {
|
||||
t, ok := mb.topics[topic]
|
||||
if !ok {
|
||||
t = &Topic{Name: topic, Created: time.Now()}
|
||||
|
@ -415,6 +411,14 @@ func (mb *MessageBus) NewTopic(topic string) *Topic {
|
|||
return t
|
||||
}
|
||||
|
||||
// NewTopic ...
|
||||
func (mb *MessageBus) NewTopic(topic string) *Topic {
|
||||
mb.Lock()
|
||||
defer mb.Unlock()
|
||||
|
||||
return mb.newTopic(topic)
|
||||
}
|
||||
|
||||
// NewMessage ...
|
||||
func (mb *MessageBus) NewMessage(topic *Topic, payload []byte) Message {
|
||||
defer func() {
|
||||
|
|
Načítá se…
Odkázat v novém úkolu