fix: write buffer leak if the wal flusher is cancelled when recovery (#41719)

issue: #41715

Signed-off-by: chyezh <chyezh@outlook.com>
This commit is contained in:
Zhen Ye 2025-05-10 09:32:56 +08:00 committed by GitHub
parent ff5c2770e5
commit 452d6fb709
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -168,13 +168,24 @@ func (impl *flusherComponents) recover(ctx context.Context, recoverInfos map[str
futures[vchannel] = future futures[vchannel] = future
} }
dataServices := make(map[string]*dataSyncServiceWrapper, len(futures)) dataServices := make(map[string]*dataSyncServiceWrapper, len(futures))
var lastErr error
for vchannel, future := range futures { for vchannel, future := range futures {
ds, err := future.Await() ds, err := future.Await()
if err != nil { if err != nil {
return err lastErr = err
continue
} }
dataServices[vchannel] = ds.(*dataSyncServiceWrapper) dataServices[vchannel] = ds.(*dataSyncServiceWrapper)
} }
if lastErr != nil {
// release all the data sync services if operation is canceled.
// otherwise, the write buffer will leak.
for _, ds := range dataServices {
ds.Close()
}
impl.logger.Warn("failed to build data sync service, may be canceled when recovering", zap.Error(lastErr))
return lastErr
}
impl.dataServices = dataServices impl.dataServices = dataServices
for vchannel, ds := range dataServices { for vchannel, ds := range dataServices {
ds.Start() ds.Start()

View File

@ -29,7 +29,7 @@ func RecoverWALFlusher(param *interceptors.InterceptorBuildParam) *WALFlusherImp
wal: param.WAL, wal: param.WAL,
logger: resource.Resource().Logger().With( logger: resource.Resource().Logger().With(
log.FieldComponent("flusher"), log.FieldComponent("flusher"),
zap.String("pchannel", param.ChannelInfo.Name)), zap.String("pchannel", param.ChannelInfo.String())),
metrics: newFlusherMetrics(param.ChannelInfo), metrics: newFlusherMetrics(param.ChannelInfo),
} }
go flusher.Execute() go flusher.Execute()