mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-17 00:43:36 +00:00
Merge pull request #1984 from Ace-Tang/fix-monitor-hang
monitor: enlarge watch buffer
This commit is contained in:
commit
9a6e299827
@ -12,7 +12,10 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultCheckInterval = 1 * time.Second
|
const (
|
||||||
|
defaultCheckInterval = 1 * time.Second
|
||||||
|
watcherChannelSize = 128
|
||||||
|
)
|
||||||
|
|
||||||
type monitor struct {
|
type monitor struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
@ -37,7 +40,7 @@ func (m *monitor) newWatcher() (chan error, error) {
|
|||||||
m.Lock()
|
m.Lock()
|
||||||
defer m.Unlock()
|
defer m.Unlock()
|
||||||
|
|
||||||
watcher := make(chan error, 1)
|
watcher := make(chan error, watcherChannelSize)
|
||||||
m.watchers = append(m.watchers, watcher)
|
m.watchers = append(m.watchers, watcher)
|
||||||
|
|
||||||
if !m.running {
|
if !m.running {
|
||||||
@ -83,7 +86,14 @@ func (m *monitor) notify(err error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
for _, c := range m.watchers {
|
for _, c := range m.watchers {
|
||||||
c <- err
|
// throw away message can not write to channel
|
||||||
|
// make it not stuck, the first error is useful.
|
||||||
|
select {
|
||||||
|
case c <- err:
|
||||||
|
|
||||||
|
default:
|
||||||
|
virtLog.WithField("channel-size", watcherChannelSize).Warnf("watcher channel is full, throw notify message")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +108,8 @@ func (m *monitor) stop() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.stopCh <- true
|
||||||
defer func() {
|
defer func() {
|
||||||
m.stopCh <- true
|
|
||||||
m.watchers = nil
|
m.watchers = nil
|
||||||
m.running = false
|
m.running = false
|
||||||
}()
|
}()
|
||||||
|
Loading…
Reference in New Issue
Block a user