dymensionxyz / dymint

Sequencing Engine for Dymension RollApps
Other
97 stars 67 forks source link

Resource leak in the websocket handler #892

Closed zale144 closed 3 months ago

zale144 commented 3 months ago

There is a resource leak in the websocket handler, the goroutine sendLoop is being held past the handler lifetime, due to a channel not being closed at the end of the handler. For each new ws connection, a new goroutine will be spawned and left dangling, never to be garbage collected. Goroutines are about 2kb in size, so after a 1000 connections, we have 2mb of memory taken, after a 1000,000 connections 2gb (not counting the empty channel size, which could be around 0.1kb)

Queue channel created but never closed: https://github.com/dymensionxyz/dymint/blob/1829fd00e0309a1187bd6b1a607c931b63aa9592/rpc/json/ws.go#L63

Goroutine ranging over that channel indefinitely: https://github.com/dymensionxyz/dymint/blob/1829fd00e0309a1187bd6b1a607c931b63aa9592/rpc/json/ws.go#L66