<commit_before>package client

import (
	"sync"

	"github.com/micro/go-micro/transport"
)

type pool struct {
	tr transport.Transport

	sync.Mutex
	conns map[string][]*poolConn
}

type poolConn struct {
	transport.Client
}

var (
	maxIdleConn = 2
)

func newPool() *pool {
	return &pool{
		conns: make(map[string][]*poolConn),
	}
}

// NoOp the Close since we manage it
func (p *poolConn) Close() error {
	return nil
}

func (p *pool) getConn(addr string, tr transport.Transport, opts ...transport.DialOption) (*poolConn, error) {
	p.Lock()
	conns, ok := p.conns[addr]
	// no free conn
	if !ok || len(conns) == 0 {
		p.Unlock()
		// create new conn
		c, err := tr.Dial(addr, opts...)
		if err != nil {
			return nil, err
		}
		return &poolConn{c}, nil
	}

	conn := conns[len(conns)-1]
	p.conns[addr] = conns[:len(conns)-1]
	p.Unlock()
	return conn, nil
}

func (p *pool) release(addr string, conn *poolConn, err error) {
	// don't store the conn
	if err != nil {
		conn.Client.Close()
		return
	}

	// otherwise put it back
	p.Lock()
	conns := p.conns[addr]
	if len(conns) >= maxIdleConn {
		conn.Client.Close()
		return
	}
	p.conns[addr] = append(conns, conn)
	p.Unlock()
}<commit_msg>Noobed the deadlock<commit_after>package client

import (
	"sync"

	"github.com/micro/go-micro/transport"
)

type pool struct {
	tr transport.Transport

	sync.Mutex
	conns map[string][]*poolConn
}

type poolConn struct {
	transport.Client
}

var (
	maxIdleConn = 2
)

func newPool() *pool {
	return &pool{
		conns: make(map[string][]*poolConn),
	}
}

// NoOp the Close since we manage it
func (p *poolConn) Close() error {
	return nil
}

func (p *pool) getConn(addr string, tr transport.Transport, opts ...transport.DialOption) (*poolConn, error) {
	p.Lock()
	conns, ok := p.conns[addr]
	// no free conn
	if !ok || len(conns) == 0 {
		p.Unlock()
		// create new conn
		c, err := tr.Dial(addr, opts...)
		if err != nil {
			return nil, err
		}
		return &poolConn{c}, nil
	}

	conn := conns[len(conns)-1]
	p.conns[addr] = conns[:len(conns)-1]
	p.Unlock()
	return conn, nil
}

func (p *pool) release(addr string, conn *poolConn, err error) {
	// don't store the conn
	if err != nil {
		conn.Client.Close()
		return
	}

	// otherwise put it back
	p.Lock()
	conns := p.conns[addr]
	if len(conns) >= maxIdleConn {
		p.Unlock()
		conn.Client.Close()
		return
	}
	p.conns[addr] = append(conns, conn)
	p.Unlock()
}
{'fraction_non_alphanumeric': 0.15934755332496864, 'fraction_numerical': 0.003345880384776244, 'mean_word_length': 3.3570127504553735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6673721', 'n_tokens_mistral': 991, 'n_tokens_neox': 946, 'n_words': 247}