Skip to content

MongoObservationCommandListener causes memory leak #5064

@michaldo

Description

@michaldo

Spring data mongodb 4.5.4

I use https://docs.spring.io/spring-data/mongodb/reference/observability/observability.html and https://docs.spring.io/spring-data/mongodb/reference/mongodb/change-streams.html#change-streams-with-messagelistener

I have one change stream listener with one thread which runs continously

When I debug listener thread and method MongoObservationCommandListener#commandStarted, I see in first call parent observation is null

L117

Found the following observation passed from the mongo context [null]

And in L123 new observation is created, let name it O1

In next call, I see

Found the following observation passed from the mongo context: O1

(of cource it is no "O1" but long json describing O1)

And in L123 new observation O2 is created and in L128 O2.setParent(O1)

In next call, I see

Found the following observation passed from the mongo context: O2

And in L123 new observation O3 is created and in L128 O3.setParent(O2)

Over and over up to OOM

Additionally, when logs are enabled, the following contradictory sequence is printed

mongo-listener] [] [-] [ / ] o.s.d.m.o.MongoObservationCommandListener: Instrumenting the command started event
mongo-listener] [] [-] [ / ] o.s.d.m.o.MongoObservationCommandListener: No observation was found - will not create any child observations
mongo-listener] [] [-] [ / ] o.s.d.m.o.MongoObservationCommandListener: Found the following observation passed from the mongo context [null]
mongo-listener] [] [-] [ / ] o.s.d.m.o.MongoObservationCommandListener: Created a child observation [{name=spring.data.mongodb.command(null)...****

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions