Skip to content
Golang net.Conn Connection Pool
Branch: master
Clone or download
sabey added support for IdleTimeout
if IdleTimeout is above 0 support for removing idle connections is enabled
once a connection is moved to the available map, ticker will start and will watch and remove idle connections from our pool
when there are no available connections (ie: all connections are active or there are no connections at all) our ticker will not run
Latest commit 972bd0a Sep 5, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE init Sep 4, 2018 init Sep 4, 2018
buffer.go init Sep 4, 2018
config.go added support for IdleTimeout Sep 5, 2018
connection.go added support for IdleTimeout Sep 5, 2018
error.go init Sep 4, 2018
lagoon.go added support for IdleTimeout Sep 5, 2018
lagoon_test.go added support for IdleTimeout Sep 5, 2018
lagoon_tick.go added support for IdleTimeout Sep 5, 2018


Golang net.Conn Connection Pool


This package was inspired by - This is NOT a fork, it will function differently!!!

The main differences are:

  • The connection pool is capped and Dial will block once the pool is full!
  • Connections are capped with a Buffer that can be optionally shared between pools.
  • Dial can Timeout if we fail to acquire a spot from the Buffer queue! (DialTimeout or similar should be used within the Dial function)
  • DialInitial can not garauntee that we will always dial the initial amount due to the possibility of a shared Buffer.


go get -t -u


// create a shared buffer
buffer := CreateBuffer(10, time.Second*2)

// create a config for our lagoon instance
config := &Config{
	Dial: func() (net.Conn, error) {
		return net.DialTimeout("tcp", "service.local:25", time.Second*30)
	DialInitial: 5,
	Buffer:      buffer,

// create a lagoon instance
l, err := CreateLagoon(config)

// dial
c, err := l.Dial()

// return connection back to the pool

// dial
c, err := l.Dial()

// remove connection from the pool on close

// close connection
You can’t perform that action at this time.