My agentic slop goes here. Not intended for anyone else!

more

Changed files
+11 -20
stack
conpool
+10 -19
stack/conpool/lib/conpool.ml
···
let src = Logs.Src.create "conpool" ~doc:"Connection pooling library"
module Log = (val Logs.src_log src : Logs.LOG)
-
(** {1 Public Module Types} *)
-
module Endpoint = struct
type t = {
host : string;
···
endpoint : Endpoint.t;
}
-
let get_flow t = t.flow
let endpoint t = t.endpoint
let created_at t = t.created_at
let last_used t = t.last_used
···
t.errors
end
-
(** {1 Internal Types} *)
-
-
type endpoint_stats_mutable = {
mutable active : int;
mutable idle : int;
mutable total_created : int;
···
type endpoint_pool = {
pool : Connection.t Eio.Pool.t;
-
stats : endpoint_stats_mutable;
mutex : Eio.Mutex.t;
}
···
endpoints_mutex : Eio.Mutex.t;
}
-
(** {1 Endpoint Hashing} *)
-
module EndpointTbl = Hashtbl.Make(struct
type t = Endpoint.t
let equal = Endpoint.equal
let hash = Endpoint.hash
end)
-
(** {1 Helper Functions} *)
-
let get_time pool =
Eio.Time.now pool.clock
-
let create_mutable_stats () = {
active = 0;
idle = 0;
total_created = 0;
···
errors = 0;
}
-
let snapshot_stats (stats : endpoint_stats_mutable) : Stats.t = {
active = stats.active;
idle = stats.idle;
total_created = stats.total_created;
···
(** {1 DNS Resolution} *)
let resolve_endpoint pool endpoint =
-
(* Simple DNS resolution - returns socket address *)
Log.debug (fun m -> m "Resolving %a..." Endpoint.pp endpoint);
let addrs = Eio.Net.getaddrinfo_stream pool.net (Endpoint.host endpoint) ~service:(string_of_int (Endpoint.port endpoint)) in
Log.debug (fun m -> m "Got address list for %a" Endpoint.pp endpoint);
···
Log.debug (fun m -> m "TCP connection established to %a" Endpoint.pp endpoint);
-
let flow : [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t = match pool.tls with
| None -> (socket :> [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t)
| Some tls_cfg ->
Log.debug (fun m -> m "Initiating TLS handshake with %a" Endpoint.pp endpoint);
···
else if (match pool.config.health_check with
| Some check ->
(try
-
let healthy = check (Connection.get_flow conn) in
if not healthy then
Log.debug (fun m -> m "Connection to %a failed custom health check"
Endpoint.pp (Connection.endpoint conn));
···
Eio.Cancel.protect (fun () ->
try
-
Eio.Flow.close (Connection.get_flow conn)
with _ -> ()
);
···
ep_pool
| None ->
(* Create new endpoint pool *)
-
let stats = create_mutable_stats () in
let mutex = Eio.Mutex.create () in
Log.info (fun m -> m "Creating new endpoint pool for %a (max_connections=%d)"
···
(* Run health check if configured *)
match pool.config.health_check with
| Some check ->
-
(try check (Connection.get_flow conn)
with _ -> false)
| None -> true
) else begin
···
let src = Logs.Src.create "conpool" ~doc:"Connection pooling library"
module Log = (val Logs.src_log src : Logs.LOG)
module Endpoint = struct
type t = {
host : string;
···
endpoint : Endpoint.t;
}
+
let flow t = t.flow
let endpoint t = t.endpoint
let created_at t = t.created_at
let last_used t = t.last_used
···
t.errors
end
+
type endp_stats = {
mutable active : int;
mutable idle : int;
mutable total_created : int;
···
type endpoint_pool = {
pool : Connection.t Eio.Pool.t;
+
stats : endp_stats;
mutex : Eio.Mutex.t;
}
···
endpoints_mutex : Eio.Mutex.t;
}
module EndpointTbl = Hashtbl.Make(struct
type t = Endpoint.t
let equal = Endpoint.equal
let hash = Endpoint.hash
end)
let get_time pool =
Eio.Time.now pool.clock
+
let create_endp_stats () = {
active = 0;
idle = 0;
total_created = 0;
···
errors = 0;
}
+
let snapshot_stats (stats : endp_stats) : Stats.t = {
active = stats.active;
idle = stats.idle;
total_created = stats.total_created;
···
(** {1 DNS Resolution} *)
let resolve_endpoint pool endpoint =
Log.debug (fun m -> m "Resolving %a..." Endpoint.pp endpoint);
let addrs = Eio.Net.getaddrinfo_stream pool.net (Endpoint.host endpoint) ~service:(string_of_int (Endpoint.port endpoint)) in
Log.debug (fun m -> m "Got address list for %a" Endpoint.pp endpoint);
···
Log.debug (fun m -> m "TCP connection established to %a" Endpoint.pp endpoint);
+
let flow = match pool.tls with
| None -> (socket :> [`Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t)
| Some tls_cfg ->
Log.debug (fun m -> m "Initiating TLS handshake with %a" Endpoint.pp endpoint);
···
else if (match pool.config.health_check with
| Some check ->
(try
+
let healthy = check (Connection.flow conn) in
if not healthy then
Log.debug (fun m -> m "Connection to %a failed custom health check"
Endpoint.pp (Connection.endpoint conn));
···
Eio.Cancel.protect (fun () ->
try
+
Eio.Flow.close (Connection.flow conn)
with _ -> ()
);
···
ep_pool
| None ->
(* Create new endpoint pool *)
+
let stats = create_endp_stats () in
let mutex = Eio.Mutex.create () in
Log.info (fun m -> m "Creating new endpoint pool for %a (max_connections=%d)"
···
(* Run health check if configured *)
match pool.config.health_check with
| Some check ->
+
(try check (Connection.flow conn)
with _ -> false)
| None -> true
) else begin
+1 -1
stack/conpool/lib/conpool.mli
···
type t
(** Opaque connection handle with metadata *)
-
val get_flow : t -> [ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t
(** Extract underlying Eio flow from connection *)
val endpoint : t -> Endpoint.t
···
type t
(** Opaque connection handle with metadata *)
+
val flow : t -> [ `Close | `Flow | `R | `Shutdown | `W] Eio.Resource.t
(** Extract underlying Eio flow from connection *)
val endpoint : t -> Endpoint.t