Skip to content

fix:[2.5] analyzer memory leak because function runner not close #41840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/datanode/importv2/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
if err != nil {
return err
}
defer runner.Close()

Check warning on line 217 in internal/datanode/importv2/util.go

View check run for this annotation

Codecov / codecov/patch

internal/datanode/importv2/util.go#L217

Added line #L217 was not covered by tests

inputFieldIDs := lo.Map(runner.GetInputFields(), func(field *schemapb.FieldSchema, _ int) int64 { return field.GetFieldID() })
inputDatas := make([]any, 0, len(inputFieldIDs))
Expand Down
6 changes: 6 additions & 0 deletions internal/flushcommon/pipeline/flow_graph_embedding_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
return []Msg{fgMsg}
}

func (eNode *embeddingNode) Close() {
for _, runner := range eNode.functionRunners {
runner.Close()
}

Check warning on line 171 in internal/flushcommon/pipeline/flow_graph_embedding_node.go

View check run for this annotation

Codecov / codecov/patch

internal/flushcommon/pipeline/flow_graph_embedding_node.go#L168-L171

Added lines #L168 - L171 were not covered by tests
}

func BuildSparseFieldData(array *schemapb.SparseFloatArray) storage.FieldData {
return &storage.SparseFloatVectorFieldData{
SparseFloatArray: schemapb.SparseFloatArray{
Expand Down
6 changes: 6 additions & 0 deletions internal/querynodev2/pipeline/embedding_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@
return nodeMsg
}

func (eNode *embeddingNode) Close() {
for _, functionRunner := range eNode.functionRunners {
functionRunner.Close()
}

Check warning on line 209 in internal/querynodev2/pipeline/embedding_node.go

View check run for this annotation

Codecov / codecov/patch

internal/querynodev2/pipeline/embedding_node.go#L206-L209

Added lines #L206 - L209 were not covered by tests
}

func getEmbeddingFieldDatas(datas []*schemapb.FieldData, fieldIDs ...int64) ([]any, error) {
result := []any{}
for _, fieldID := range fieldIDs {
Expand Down
4 changes: 4 additions & 0 deletions internal/util/function/bm25_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@
return []*schemapb.FieldSchema{v.inputField}
}

func (v *BM25FunctionRunner) Close() {
v.tokenizer.Destroy()

Check warning on line 175 in internal/util/function/bm25_function.go

View check run for this annotation

Codecov / codecov/patch

internal/util/function/bm25_function.go#L174-L175

Added lines #L174 - L175 were not covered by tests
}

func buildSparseFloatArray(mapdata []map[uint32]float32) *schemapb.SparseFloatArray {
dim := int64(0)
bytes := lo.Map(mapdata, func(sparseMap map[uint32]float32, _ int) []byte {
Expand Down
2 changes: 2 additions & 0 deletions internal/util/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type FunctionRunner interface {
GetSchema() *schemapb.FunctionSchema
GetOutputFields() []*schemapb.FieldSchema
GetInputFields() []*schemapb.FieldSchema

Close()
}

func NewFunctionRunner(coll *schemapb.CollectionSchema, schema *schemapb.FunctionSchema) (FunctionRunner, error) {
Expand Down
40 changes: 36 additions & 4 deletions internal/util/function/mock_function.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions internal/util/function/multi_analyzer_bm25_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,9 @@
func (v *MultiAnalyzerBM25FunctionRunner) GetInputFields() []*schemapb.FieldSchema {
return v.inputFields
}

func (v *MultiAnalyzerBM25FunctionRunner) Close() {
for _, analyzer := range v.analyzers {
analyzer.Destroy()
}

Check warning on line 242 in internal/util/function/multi_analyzer_bm25_function.go

View check run for this annotation

Codecov / codecov/patch

internal/util/function/multi_analyzer_bm25_function.go#L239-L242

Added lines #L239 - L242 were not covered by tests
}
5 changes: 5 additions & 0 deletions internal/util/pipeline/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Node interface {
Name() string
MaxQueueLength() int32
Operate(in Msg) Msg

Close()
}

type nodeCtx struct {
Expand Down Expand Up @@ -56,6 +58,9 @@ func (node *BaseNode) MaxQueueLength() int32 {
return node.maxQueueLength
}

func (node *BaseNode) Close() {
}

func NewBaseNode(name string, maxQueryLength int32) *BaseNode {
return &BaseNode{
name: name,
Expand Down
1 change: 1 addition & 0 deletions internal/util/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (p *pipeline) Start() error {

func (p *pipeline) Close() {
for _, node := range p.nodes {
node.node.Close()
if node.Checker != nil {
node.Checker.Close()
}
Expand Down
Loading