Handle the stream sending in thread safe way

This commit is contained in:
Zoltan Papp
2023-06-28 02:08:09 +02:00
parent 649dbf2bed
commit ca1722ed10
2 changed files with 5 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ func (k *KeepAlive) StreamInterceptor() grpc.StreamServerInterceptor {
}
m := &ioMonitor{
sync.Mutex{},
sync.Mutex{},
stream,
time.Now(),

View File

@@ -8,13 +8,16 @@ import (
)
type ioMonitor struct {
mu sync.Mutex
mu sync.Mutex
streamLock sync.Mutex
grpc.ServerStream
lastSeen time.Time
}
func (l *ioMonitor) sendMsg(m interface{}) error {
l.updateLastSeen()
l.streamLock.Lock()
defer l.streamLock.Unlock()
return l.ServerStream.SendMsg(m)
}