@@ -40,15 +40,19 @@ let debug = if debug_enabled then debug else ignore_log
4040type endpoint = {host : string ; port : int }
4141
4242(* Need to limit the absolute number of stunnels as well as the maximum age *)
43- let max_stunnel = 70
43+ let max_stunnel = Atomic. make 70
4444
45- let max_age = 180. *. 60. (* seconds *)
45+ let set_max_stunnel n =
46+ D. info " Setting max_stunnel = %d" n ;
47+ Atomic. set max_stunnel n
4648
47- let max_idle = 5. *. 60. (* seconds *)
49+ let max_age = ref (180. *. 60. ) (* seconds *)
50+
51+ let max_idle = ref (5. *. 60. ) (* seconds *)
4852
4953(* The add function adds the new stunnel before doing gc, so the cache *)
5054(* can briefly contain one more than maximum. *)
51- let capacity = max_stunnel + 1
55+ let capacity = Atomic. get max_stunnel + 1
5256
5357(* * An index of endpoints to stunnel IDs *)
5458let index : (endpoint, int list) Hashtbl.t ref = ref (Hashtbl. create capacity)
@@ -104,6 +108,7 @@ let unlocked_gc () =
104108 let to_gc = ref [] in
105109 (* Find the ones which are too old *)
106110 let now = Unix. gettimeofday () in
111+ let max_age = ! max_age and max_idle = ! max_idle in
107112 Tbl. iter ! stunnels (fun idx stunnel ->
108113 match Hashtbl. find_opt ! times idx with
109114 | Some time ->
@@ -122,6 +127,7 @@ let unlocked_gc () =
122127 debug " %s: found no entry for idx=%d" __FUNCTION__ idx
123128 ) ;
124129 let num_remaining = List. length all_ids - List. length ! to_gc in
130+ let max_stunnel = Atomic. get max_stunnel in
125131 if num_remaining > max_stunnel then (
126132 let times' = Hashtbl. fold (fun k v acc -> (k, v) :: acc) ! times [] in
127133 let times' =
0 commit comments