You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Appreciate if you could check my solution for this issue.
Problem
The cluster service currently creates a new goroutine for every incoming connection without any limit.
This can become a problem if too many connections are opened at once. A large number of goroutines increases memory usage heavily and may eventually cause the server to run out of memory and crash.
For example, if an attacker or client opens thousands of connections continuously, the server may create thousands of goroutines and become unstable.
Proposed Solution
Use a bounded worker pool to control how many connections are handled at the same time.
Suggested approach:
Create a fixed number of worker goroutines (for example: 100)
Store incoming connections in a buffered queue
Workers pick connections from the queue and process them
Add proper synchronization and graceful shutdown handling
This prevents unlimited goroutine creation and makes connection handling more predictable and memory-safe.
That is the wrong approach, and not how systems solve the problem. Opening goroutines ahead of time is wasteful.
Instead you count the number of connections in use (there is already a goroutine spun up per connection) and when the next connection attempt that comes in that would exceed the max count you don't answer it or you block waiting for a goroutine to come free. This is normally done in Go with channels of a fixed capacity.
Take a look at Go concurrency patterns online, especially those concerning channels.
Activity
fix: add connection limit tracking to cluster Service
DARSHANR007 commentedon May 20, 2026
Hey @otoolep
Appreciate if you could check my solution for this issue.
Problem
The cluster service currently creates a new goroutine for every incoming connection without any limit.
This can become a problem if too many connections are opened at once. A large number of goroutines increases memory usage heavily and may eventually cause the server to run out of memory and crash.
For example, if an attacker or client opens thousands of connections continuously, the server may create thousands of goroutines and become unstable.
Proposed Solution
Use a bounded worker pool to control how many connections are handled at the same time.
Suggested approach:
This prevents unlimited goroutine creation and makes connection handling more predictable and memory-safe.
otoolep commentedon May 20, 2026
That is the wrong approach, and not how systems solve the problem. Opening goroutines ahead of time is wasteful.
Instead you count the number of connections in use (there is already a goroutine spun up per connection) and when the next connection attempt that comes in that would exceed the max count you don't answer it or you block waiting for a goroutine to come free. This is normally done in Go with channels of a fixed capacity.
Take a look at Go concurrency patterns online, especially those concerning channels.