lerenn / asyncapi-codegen

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!
Apache License 2.0
91 stars 23 forks source link

Memory leak in SubscribeTo #240

Closed nuttert closed 3 months ago

nuttert commented 3 months ago

Hey! I noticed that my server memory grows linearly:

image

then created two snapshots of the heap and visualized their difference:

image

And think that the problem in the code(in the SubscribeTo method):

 ctx = context.WithValue(ctx, extensions.ContextKeyIsBrokerMessage, acknowledgeableBrokerMessage.String())

First of all, why do you serialize full message? The message could be 8 mb and it seems that if we do not a debug, we don't need it. And second point, that I don't understand why the sub context has not finished, also there are no deadlines for it. I thought may be problem in my code that it holds the context, but as you can see the problem also in a ping handler(the server gets about 3000 ping every minute), it almost empty without logic

lerenn commented 3 months ago

Hello @nuttert ! Thanks for taking time to fill in an issue :)

Arf, the serialization was intended for debug purposes if someone wanted to log the message content. It should be made optionable.

I was expecting the context to just be garbage collected after the call. I'll add a deadline to it. Thanks for pointing this !

Feel free to give more info if you stumble on anything else !

lerenn commented 3 months ago

I think it should be good now.

Please keep me informed if the problem is still there :)