go-socket.io icon indicating copy to clipboard operation
go-socket.io copied to clipboard

bug: memory leak happening.

Open piksonGit opened this issue 3 years ago • 29 comments

when i connect 170000+ clients using go-socket.io. the memory use keep growing even I just connect and do nothing.

To Reproduce Brief code to reproduce the behavior.

Expected behavior A clear and concise description of what you expected to happen. memory leak. memory keep growing until oom. Environment (please complete the following information):

  • Go version: [e.g. v1.16]
  • Server version [e.g. go-socket.io v1.4.5]

Additional context

server.OnEvent("/notification", "toServer", func(s socketio.Conn, msg interface{}) {

	noti := msg.(map[string]interface{})

On Linux 3.10 centos7.

here is the heap.out
4729.28MB 28.89% 28.89%  4729.28MB 28.89%  bufio.NewWriterSize
 2924.13MB 17.86% 46.75%  2924.13MB 17.86%  bufio.NewReaderSize
 1416.50MB  8.65% 55.40%  1416.50MB  8.65%  bytes.makeSlice
  884.06MB  5.40% 60.80%   884.06MB  5.40%  io.copyBuffer
  861.35MB  5.26% 66.07%   912.86MB  5.58%  net/textproto.(*Reader).ReadMIMEHeader
  575.21MB  3.51% 69.58%   575.21MB  3.51%  runtime.malg
  568.47MB  3.47% 73.05%   568.47MB  3.47%  crypto/tls.Server
  389.62MB  2.38% 75.43%   389.62MB  2.38%  crypto/aes.(*aesCipherGCM).NewGCM
  275.08MB  1.68% 77.11%   298.08MB  1.82%  github.com/gorilla/websocket.newConn
  246.04MB  1.50% 78.62%   275.54MB  1.68%  github.com/googollee/go-socket.io/engineio/transport/websocket.newConn

here is the memestat:

 runtime.MemStats
# Alloc = 18400272336
# TotalAlloc = 169292392264
# Sys = 26073060600
# Lookups = 0
# Mallocs = 454336696
# Frees = 399619454
# HeapAlloc = 18400272336
# HeapSys = 18543607808
# HeapIdle = 63258624
# HeapInuse = 18480349184
# HeapReleased = 63258624
# HeapObjects = 54717242
# Stack = 6284509184 / 6284509184
# MSpan = 236746760 / 237682688
# MCache = 9600 / 16384
# BuckHashSys = 1938927
# GCSys = 880963976
# OtherSys = 124341633
# NextGC = 20642027808
# LastGC = 1620124870612394983

# NumForcedGC = 0
# GCCPUFraction = 0.08189029859571963
# DebugGC = false
# MaxRSS = 26046468096

I use gin and https


	web.Routes(router, server)
	router.RunTLS(":443", "./certification/*.infinitynewtab.com.pem", "./certification/*.infinitynewtab.com.key")

the CLOSE_WAIT is too much and keep growing

213105 CLOSE_WAIT 17 CLOSING 181753 ESTABLISHED 24 FIN_WAIT1 2 FIN_WAIT2 222 LAST_ACK 7 LISTEN 256 SYN_RECV 1 SYN_SENT 49 TIME_WAIT

piksonGit avatar Apr 29 '21 10:04 piksonGit

Hey, @piksonGit It does not actually?

sshaplygin avatar May 02 '21 10:05 sshaplygin

Hey, @piksonGit It does not actually?

yes, it's happening. my server have 64G memory. it ran out.

piksonGit avatar May 02 '21 11:05 piksonGit

I will try to fix this issue. Thanks you feedback

sshaplygin avatar May 02 '21 12:05 sshaplygin

I will try to fix this issue. Thanks you feedback

should I use s.Close() in OnDisconnect or OnError method?

piksonGit avatar May 08 '21 09:05 piksonGit

I will try to fix this issue. Thanks you feedback

Is it fixed? I also encountered this problem!

iGoogle-ink avatar May 21 '21 10:05 iGoogle-ink

Hey, Jerry! Sorry, for slow answer, it is in progress

sshaplygin avatar May 21 '21 10:05 sshaplygin

To https://github.com/googollee/go-socket.io/issues/442#issuecomment-835250470, please call Close() in OnError() when you don't want to continue the session. It's also safe to call Close() in OnDisconnect().

googollee avatar May 21 '21 19:05 googollee

To #442 (comment), please call Close() in OnError() when you don't want to continue the session. It's also safe to call Close() in OnDisconnect().

I will have a try

iGoogle-ink avatar May 24 '21 05:05 iGoogle-ink

To #442 (comment), please call Close() in OnError() when you don't want to continue the session. It's also safe to call Close() in OnDisconnect().

I will have a try

Do you fix the problems?

piksonGit avatar May 27 '21 04:05 piksonGit

To #442 (comment), please call Close() in OnError() when you don't want to continue the session. It's also safe to call Close() in OnDisconnect().

I will have a try

Do you fix the problems?

No,not solved

iGoogle-ink avatar May 27 '21 05:05 iGoogle-ink

I also encountered this problem! Hope for fixed it

jamaltan avatar Jun 24 '21 03:06 jamaltan

hi guys, anyone solved this issue? anyway my swarm node stuck at 98% RAM Usage without any user on it anymore, am i facing the same problem or what?

kingter-sutjiadi avatar Aug 25 '21 11:08 kingter-sutjiadi

Easy to duplicate the issue. Suggestion from https://github.com/googollee/go-socket.io/issues/442#issuecomment-846219126 can't work.

Screen Shot 2021-10-17 at 11 34 02 PM

appleboy avatar Oct 17 '21 15:10 appleboy

Is this problem fixed now?

jialeo avatar Jan 05 '22 09:01 jialeo

Has the problem been solved? I have this problem, too? Showing top 10 nodes out of 58 flat flat% sum% cum cum% 32.63MB 30.49% 30.49% 32.63MB 30.49% bufio.NewWriterSize 28.10MB 26.26% 56.75% 28.10MB 26.26% bufio.NewReaderSize 9MB 8.41% 65.16% 9MB 8.41% runtime.malg 7MB 6.54% 71.70% 7MB 6.54% net/textproto.(*Reader).ReadMIMEHeader 5.50MB 5.14% 76.84% 5.50MB 5.14% github.com/gorilla/websocket.newConn 5MB 4.67% 81.52% 5MB 4.67% github.com/googollee/go-socket.io/engineio/transport/websocket.newConn 4MB 3.74% 85.26% 6.50MB 6.07% github.com/googollee/go-socket%2eio.newConn 3MB 2.80% 88.06% 3MB 2.80% net.newFD 2MB 1.87% 89.93% 2MB 1.87% syscall.anyToSockaddr 1.50MB 1.40% 91.33% 1.50MB 1.40% github.com/googollee/go-socket%2eio.(*namespaces).Set

dmskys avatar Jan 19 '22 13:01 dmskys

I tried call Close() in OnDisconnect(), but the sessions count still increase. Is there any solution for this problem?

nkcc avatar Jan 26 '22 03:01 nkcc

hello bro, is this problem fixed now?

fsmytsai avatar Feb 23 '22 08:02 fsmytsai

nope, there is a PR that commit by @sshaplygin , I have tried it. This problem still exists.

nkcc avatar Feb 25 '22 01:02 nkcc

any updates ?

ElegantSoft avatar May 04 '22 17:05 ElegantSoft

no update

Abanoub Istfanous @.***> 于2022年5月5日周四 01:06写道:

any updates ?

— Reply to this email directly, view it on GitHub https://github.com/googollee/go-socket.io/issues/442#issuecomment-1117594594, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACJZDZVHNXVPVX2743UKRGTVIKVAHANCNFSM43ZSN7KQ . You are receiving this because you were mentioned.Message ID: @.***>

piksonGit avatar May 20 '22 01:05 piksonGit

Hey, @piksonGit ! I merged fix for this problem. Please check up updates on this version

Do you have any time to check leak in your project?

sshaplygin avatar May 20 '22 07:05 sshaplygin

Hey, @piksonGit ! I merged fix for this problem. Please check up updates on this version

Do you have any time to check leak in your project?

hey.glad to hear that.I'll do test on my project. then I'll reply. thank you!

piksonGit avatar May 23 '22 01:05 piksonGit

the problem is the same with before. more and more CLOSE_WAIT then the program was killed.

piksonGit avatar Jun 10 '22 07:06 piksonGit

Hey, @piksonGit ! I merged fix for this problem. Please check up updates on this version

Do you have any time to check leak in your project?

my server go version is go1.15.5. Should I upgrade my go version?

piksonGit avatar Jun 10 '22 07:06 piksonGit

my server go version is go1.15.5. Should I upgrade my go version?

if you can testing new version on part of your clients, you will upgrade to new version

sshaplygin avatar Jun 10 '22 08:06 sshaplygin

Any Updates?

ElegantSoft avatar Nov 24 '22 13:11 ElegantSoft

It seems to me that the problem is that after disconnecting the client from the server, the number of connections does not decrease.

With each new connection, an engineio.Server.session session is created in engineio.Server, and after the client is disconnected, the session does not go anywhere.

if use recommendations from https://github.com/googollee/go-socket.io/issues/442#issuecomment-846219126 then we get problem described here https://github.com/googollee/go-socket.io/issues/442#issuecomment-945146037 So many goroutines are being created.

vortex92 avatar Jan 12 '23 18:01 vortex92

Is it fixed? I also encountered this problem!on v1.6.2

jaygno avatar Feb 03 '23 03:02 jaygno

Is it fixed? I also encountered this problem!on v1.6.1

jqiris avatar Apr 03 '23 02:04 jqiris