fix: wal may panics when context canceled (#40265)

issue: #40264

- wal may panics when context canceled
- scanner may data race when closing

Signed-off-by: chyezh <chyezh@outlook.com>
This commit is contained in:
Zhen Ye 2025-02-28 17:41:58 +08:00 committed by GitHub
parent 9a8d94998a
commit 2ff657f2d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -98,7 +98,9 @@ func (s *scannerAdaptorImpl) execute() {
s.logger.Info("scanner start background task")
msgChan := make(chan message.ImmutableMessage)
ch := make(chan struct{})
defer func() { <-ch }()
// TODO: optimize the extra goroutine here after msgstream is removed.
go func() {
defer close(ch)
@ -116,9 +118,6 @@ func (s *scannerAdaptorImpl) execute() {
return
}
s.logger.Warn("the consuming event loop of scanner is closed with unexpected error", zap.Error(err))
// waiting for the produce event loop to close.
<-ch
}
// produceEventLoop produces the message from the wal and write ahead buffer.

View File

@ -41,10 +41,14 @@ func (impl *timeTickAppendInterceptor) Ready() <-chan struct{} {
// Do implements AppendInterceptor.
func (impl *timeTickAppendInterceptor) DoAppend(ctx context.Context, msg message.MutableMessage, append interceptors.Append) (msgID message.MessageID, err error) {
cm, err := impl.operator.MVCCManager(ctx)
if err != nil {
return nil, err
}
defer func() {
if err == nil {
// the cursor manager should beready since the timetick interceptor is ready.
cm, _ := impl.operator.MVCCManager(ctx)
cm.UpdateMVCC(msg)
}
}()