Open antoniomacri opened 2 years ago
Also, it's not clear to me how that metric (ActorMailboxLength
) should work.
Shouldn't it sum the mailbox length for all the living actors?
It instead seems to replace the gauge value with the mailbox length of the last called back actor.
I'm keen to help with this issue.
Any hint on how to fix the leak and correctly implement the mailbox metric?
Thanks for the detailed report. I have to dive into this to see what the memory issue could be
It should be due to the registered callback for each actor, which keeps references to its mailbox and context via the closure.
So changing the callback logic should also fix the leak.
I'm thinking about registering a single callback in the OpenTelemetry Meter
. Go implementation of the Meter doesn't provide a way to unregister the callback (although this seems mandated by the spec...). Therefore this should be handled explicitly. WDYT?
Thanks for the response.
Describe the bug Enabling actor metrics:
causes a memory leak when actors are stopped.
To Reproduce Run the following main:
A few GB of RAM are retained even though the actors are stopped immediately after sending the data message.
By replacing
with
the memory leak disappears.
Expected behavior The memory is released when the actors are stopped.
Additional context In
props.go
the default spawner contains this code:Specifically the closure
func(goCtx context.Context)
capturesmb
andctx
, and is not unregistered after the actor is stopped.This seems to be the root cause of the memory leak.