plgd-dev / go-coap

Implementation of CoAP Server & Client in Go

Home Page:https://coap.technology

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak?

JosefWN opened this issue · comments

Hi, I'm using v2.5.0, and having what looks like a memory leak in the server component of go-coap.

Service is receiving about 0.2 rps continuously 24/7, no load spikes in terms of requests. Memory consumption is initially ~10 MB for the entire service, but it keeps climbing. At 200 MB after two weeks now, the bulk (~95%) of which is go-coap.ListenAndServe and runtime overhead.

Hi @JosefWN.

Do you use DTLS? If yes, do you use option dtls.WithInactivityMonitor() during the creation server vi dtls.NewServer()? Because the session is stored infinitely when it is not set.

For analyzing memory:
Could you look at it with https://www.freecodecamp.org/news/how-i-investigated-memory-leaks-in-go-using-pprof-on-a-large-codebase-4bec4325e192 ?

Thx

I'm not using DTLS.

Ah, I think the confusing part is the defaults. The example code and the main README.md produces code that effectively leaks connections? Is this ever desired? In long-running scenarios or under load clients will invariably connect and re-connect (especially IoT's with flaky connection, watchdogs etc.), and this adds up over time.

Seems it's not limited to DTLS:

go-coap/udp/server.go

Lines 58 to 60 in 073d2c2

createInactivityMonitor: func() inactivity.Monitor {
return inactivity.NewNilMonitor()
},

Perhaps the default should be set to something or be clarified in the README?

Yeah. Sorry about that. We will look at it. If it solves the issue you can close it.

Ok, great, thanks!