@@ -2,6 +2,7 @@ package pool
22
33import (
44 "context"
5+ "errors"
56 "log"
67 "net"
78 "net/http"
@@ -13,12 +14,15 @@ import (
1314
1415 "github.com/e2b-dev/infra/packages/shared/pkg/proxy/template"
1516 "github.com/e2b-dev/infra/packages/shared/pkg/proxy/tracking"
17+ "github.com/e2b-dev/infra/packages/shared/pkg/smap"
1618)
1719
1820type ProxyClient struct {
1921 httputil.ReverseProxy
2022
2123 transport * http.Transport
24+
25+ activeConnections * smap.Map [* tracking.Connection ]
2226}
2327
2428func newProxyClient (
@@ -30,6 +34,8 @@ func newProxyClient(
3034 currentConnsCounter * atomic.Int64 ,
3135 logger * log.Logger ,
3236) * ProxyClient {
37+ activeConnections := smap .New [* tracking.Connection ]()
38+
3339 transport := & http.Transport {
3440 Proxy : http .ProxyFromEnvironment ,
3541 // Limit the max connection per host to avoid exhausting the number of available ports to one host.
@@ -56,7 +62,7 @@ func newProxyClient(
5662 if err == nil {
5763 totalConnsCounter .Add (1 )
5864
59- return tracking .NewConnection (conn , currentConnsCounter ), nil
65+ return tracking .NewConnection (conn , currentConnsCounter , activeConnections ), nil
6066 }
6167
6268 if ctx .Err () != nil {
@@ -82,7 +88,8 @@ func newProxyClient(
8288 }
8389
8490 return & ProxyClient {
85- transport : transport ,
91+ transport : transport ,
92+ activeConnections : activeConnections ,
8693 ReverseProxy : httputil.ReverseProxy {
8794 Transport : transport ,
8895 Rewrite : func (r * httputil.ProxyRequest ) {
@@ -167,3 +174,16 @@ func newProxyClient(
167174func (p * ProxyClient ) closeIdleConnections () {
168175 p .transport .CloseIdleConnections ()
169176}
177+
178+ func (p * ProxyClient ) resetAllConnections () error {
179+ var errs []error
180+
181+ for _ , conn := range p .activeConnections .Items () {
182+ err := conn .Reset ()
183+ if err != nil {
184+ errs = append (errs , err )
185+ }
186+ }
187+
188+ return errors .Join (errs ... )
189+ }
0 commit comments