Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak #4240

Closed
thuc98 opened this issue Jan 11, 2024 · 6 comments
Closed

Memory Leak #4240

thuc98 opened this issue Jan 11, 2024 · 6 comments

Comments

@thuc98
Copy link

thuc98 commented Jan 11, 2024

I have noticed a memory leak in my server application. The memory consumption keeps increasing and is not released unless I restart the service.

Environment:

QUIC-GO Version: v0.40.1
Operating System: Linux centos 8, arch amd64
go: 1.21.2

pprof


Showing nodes accounting for 4904.20MB, 67.42% of 7273.69MB total
Dropped 352 nodes (cum <= 36.37MB)
Showing top 10 nodes out of 159
      flat  flat%   sum%        cum   cum%
 3512.39MB 48.29% 48.29%  3960.92MB 54.46%  github.com/quic-go/quic-go.(*connection).preSetup
  246.08MB  3.38% 51.67%   246.08MB  3.38%  crypto/aes.(*aesCipherGCM).NewGCM
  234.54MB  3.22% 54.90%   234.54MB  3.22%  crypto/aes.newCipher
  160.12MB  2.20% 57.10%  4539.29MB 62.41%  github.com/quic-go/quic-go.glob..func1
  148.15MB  2.04% 59.13%   148.15MB  2.04%  crypto/tls.(*Conn).quicWriteCryptoData
  138.59MB  1.91% 61.04%   138.59MB  1.91%  github.com/quic-go/quic-go.(*cryptoStreamImpl).Write
  128.69MB  1.77% 62.81%   128.69MB  1.77%  github.com/quic-go/quic-go.init.0.func1
  118.56MB  1.63% 64.44%   119.06MB  1.64%  github.com/quic-go/quic-go.(*frameSorter).push
  115.06MB  1.58% 66.02%   160.57MB  2.21%  github.com/quic-go/quic-go/internal/handshake.newCryptoSetup
  102.04MB  1.40% 67.42%   102.04MB  1.40%  crypto/tls.newQUICConn (inline)

profile005

this is how i used quic:

	udpConn, _ := net.ListenUDP("udp", &net.UDPAddr{Port: s.opts.Port})
	quicTLSCfg := tlsConfig.Clone()
	quicTLSCfg.NextProtos = []string{"quicgo"}

	s.quicListener, err = quic.Listen(udpConn, quicTLSCfg, &quic.Config{
		MaxIdleTimeout:         s.opts.MaxIdleTimeout,
		MaxIncomingStreams:     s.opts.MaxIncomingStreams,
		KeepAlivePeriod:        s.opts.KeepAlivePeriod,
		EnableDatagrams:        true,
		MaxStreamReceiveWindow: uint64(STREAM_RWND),
	})

@marten-seemann
Copy link
Member

How do you know it's a memory leak? If you have a lot of active connections, it's expected that they consume some memory.

It's only a leak if the memory persists beyond the lifetime of the connection.

@thuc98
Copy link
Author

thuc98 commented Jan 11, 2024

How do you know it's a memory leak? If you have a lot of active connections, it's expected that they consume some memory.

It's only a leak if the memory persists beyond the lifetime of the connection.

I tried closing all connections to the server but the memory hasn't decreased in the past two days

@marten-seemann
Copy link
Member

Can you build a minimal reproducer? There's no way to debug this based on your report.

@thuc98
Copy link
Author

thuc98 commented Jan 12, 2024

Can you build a minimal reproducer? There's no way to debug this based on your report.

I still haven't been able to recreate it.
But why does receivedPackets use so much memory?
5.57GB 5.57GB 480: s.receivedPackets = make(chan receivedPacket, protocol.MaxConnUnprocessedPackets)

@marten-seemann
Copy link
Member

It's a channel with 256 entries, and receivedPacket is a struct that takes 112 bytes. So for every connection, that's around 28 kB.

@thuc98
Copy link
Author

thuc98 commented Jan 17, 2024

Thank you. my fault, my connection map doesn't remove closed connection

@thuc98 thuc98 closed this as completed Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants