Skip to content

Commit

Permalink
fix: wal may panics when context canceled (#40265)
Browse files Browse the repository at this point in the history
issue: #40264

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

Signed-off-by: chyezh <[email protected]>
  • Loading branch information
chyezh authored Feb 28, 2025
1 parent 9a8d949 commit 2ff657f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 2 additions & 3 deletions internal/streamingnode/server/wal/adaptor/scanner_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()
Expand Down

0 comments on commit 2ff657f

Please sign in to comment.