Skip to content

Commit 66bce9e

Browse files
committed
Fix the order of actions we manipulate into our happy-eyeball daemon
1 parent a4b5626 commit 66bce9e

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/mnet_happy_eyeballs.ml

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ let handle_one_action t ~prms action =
105105
ignore (Miou.Computation.try_cancel waiter err)
106106
in
107107
Option.iter trans waiter
108-
| _ -> assert false
108+
| _ ->
109+
Log.err (fun m -> m "Unexpected case for Mnet_happy_eyeballs.handle_one_action");
110+
assert false
109111

110112
let to_event t = function
111113
| `Connection_failed ((id, attempt, host, addr), msg) ->
@@ -135,12 +137,14 @@ let to_event t = function
135137
if not set then Mnet.TCP.close flow
136138
end;
137139
Happy_eyeballs.Connected (host, id, addr)
138-
| _ -> assert false
140+
| _ ->
141+
Log.err (fun m -> m "Unexpected case for Mnet_happy_eyeballs.to_event");
142+
assert false
139143

140144
let now () = Int64.of_int (Mkernel.clock_monotonic ())
141145

142146
let to_actions t he user's_actions =
143-
let fold (he, actions) = function
147+
let fold (he, ractions) = function
144148
| `Connect_ip { aaaa_timeout; connect_delay; connect_timeout; state; addrs }
145149
->
146150
let waiters, id = HE.Waiter_map.register state t.waiters in
@@ -149,8 +153,7 @@ let to_actions t he user's_actions =
149153
HE.connect_ip he (now ()) ?aaaa_timeout ?connect_delay
150154
?connect_timeout ~id addrs
151155
in
152-
(he, actions @ actions')
153-
(* TODO(dinosaure): [List.rev_append]? *)
156+
(he, List.rev_append actions' ractions)
154157
| `Connect
155158
{
156159
aaaa_timeout
@@ -168,8 +171,7 @@ let to_actions t he user's_actions =
168171
HE.connect he (now ()) ?aaaa_timeout ?connect_delay ?connect_timeout
169172
?resolve_timeout ?resolve_retries ~id host ports
170173
in
171-
(* TODO(dinosaure): [List.rev_append]? *)
172-
(he, actions @ actions')
174+
(he, List.rev_append actions' ractions)
173175
in
174176
List.fold_left fold (he, []) user's_actions
175177

@@ -196,9 +198,12 @@ let continue t cont he =
196198
let fn () =
197199
match cont with
198200
| `Act ->
201+
Log.debug (fun m -> m "Act (await actions or events with timeout %dns)" t.timer_interval);
199202
let fn () = await_actions_or_events t in
200203
with_timeout ~timeout:t.timer_interval fn
201-
| `Suspend -> await_actions_or_events t
204+
| `Suspend ->
205+
Log.debug (fun m -> m "Suspend (await actions or events)");
206+
await_actions_or_events t
202207
in
203208
match fn () with
204209
| `Timeout -> (he, [], [])
@@ -210,8 +215,8 @@ let continue t cont he =
210215
in
211216
List.partition_map fn actions_and_events
212217
in
213-
let he, actions = to_actions t he user's_actions in
214-
(he, actions, events)
218+
let he, ractions = to_actions t he user's_actions in
219+
(he, ractions, events)
215220
| `Exn exn -> raise exn
216221

217222
let rec clean_up prms =
@@ -225,18 +230,16 @@ let rec go t ~prms he =
225230
Log.debug (fun m -> m "happy-eyeballs tick");
226231
clean_up prms;
227232
let he, cont, actions = HE.timer he (now ()) in
228-
Log.debug (fun m -> m "%d action(s)" (List.length actions));
229233
List.iter (handle_one_action ~prms t) actions;
230-
let he, actions, events = continue t cont he in
231-
Log.debug (fun m -> m "%d action(s)" (List.length actions));
232-
let he, actions =
233-
let fn (he, actions) event =
234+
let he, ractions, events = continue t cont he in
235+
let he, ractions =
236+
let fn (he, ractions) event =
234237
let he, actions' = HE.event he (now ()) (to_event t event) in
235-
(he, List.rev_append actions actions')
238+
(he, List.rev_append actions' ractions)
236239
in
237-
List.fold_left fn (he, actions) events
240+
List.fold_left fn (he, ractions) events
238241
in
239-
List.iter (handle_one_action ~prms t) actions;
242+
List.iter (handle_one_action ~prms t) (List.rev ractions);
240243
go t ~prms he
241244

242245
let unknown _ domain_name = error_msgf "%a not found" Domain_name.pp domain_name

0 commit comments

Comments
 (0)