fed-sx-m2: resolve Blockers #4 — kernel routes now work over real HTTP
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m6s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m6s
Substrate fix: two-line change to lib/erlang/runtime.sx that lets
http-listen handler routes call gen_server:call without deadlocking.
1. er-sched-step-alive!: pass :pending-args (when set) to the
initial-fun call instead of always passing an empty list.
Default behavior (no field) stays (list) — drop-in safe.
2. er-bif-http-listen sx-handler: instead of er-apply-fun handler
inline (which blows up on receive's er-suspend-marker because
the connection thread has no scheduler step on its stack),
create a real er-process with :initial-fun = handler and
:pending-args = (list req-pl), then er-sched-run-all! to drain.
Any receive (e.g. gen_server:call) suspends + resumes inside
the SX scheduler frame the process owns. Read :exit-result
for the response proplist; marshal back to SX dict.
Investigation arc (see plans/fed-sx-milestone-2.md Blockers #4 +
Progress log):
- loops/fed-prims bf8d0bf2 diagnosed it as Erlang-substrate, not
OCaml mutex (Pattern A wrong, Pattern B right but sketchy).
- First Pattern B attempt failed: tried er-spawn-fun on a raw SX
lambda, hit (er-fun? fv) gate. Connection-thread bisect
pinpointed the exact line.
- Real fix: use the existing er-fun (user's handler) directly,
but feed it via :pending-args so step-alive's hardcoded
(list) doesn't drop the request arg.
Acceptance:
- new next/tests/smoke_kernel_route.sh: 6/6 over real HTTP
(welcome /, /actors/alice, /actors/alice/outbox with
gen_server-backed tip, /actors/alice/inbox, unknown-actor,
via http_server:start(P, [{kernel, nx_kernel}])).
- next/tests/http_server_tcp.sh: 5/5 (bumped wait_bound from
30s to 180s — cold boot is slow under sibling-loop CPU load
and the per-handler scheduler ramp adds a small margin).
- Erlang conformance: 761/761.
Step 12's two-instance smoke test is now unblocked — its full
Follow / Accept / Note flow can layer on top of this kernel-route
surface. m2 plan updated.
Pre-existing httpc_request.sh flakiness ("Undefined symbol:
http-request" on the live-call epochs) reproduces WITHOUT this
change — see git stash A/B in the investigation. Unrelated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -731,7 +731,10 @@
|
||||
0
|
||||
(if
|
||||
(= prev-k nil)
|
||||
(er-apply-fun (er-proc-field pid :initial-fun) (list))
|
||||
(er-apply-fun
|
||||
(er-proc-field pid :initial-fun)
|
||||
(let ((args (er-proc-field pid :pending-args)))
|
||||
(cond (= args nil) (list) :else args)))
|
||||
(do (er-proc-set! pid :continuation nil) (prev-k nil)))))
|
||||
(let
|
||||
((r (nth result-ref 0)))
|
||||
@@ -1612,11 +1615,31 @@
|
||||
;; 78eae9ef deleted them as dead because the BIF body
|
||||
;; still referenced them — Blockers #1. This rewrite
|
||||
;; threads through the live marshallers instead.)
|
||||
;; Run the handler as a SCHEDULED er-process so any
|
||||
;; `receive` (e.g. gen_server:call inside a kernel-aware
|
||||
;; route) suspends and resumes inside the SX scheduler.
|
||||
;; Without this, native http-listen invokes the handler
|
||||
;; closure on a fresh OCaml thread that has no scheduler
|
||||
;; frame, so the receive's er-suspend-marker propagates
|
||||
;; out and the connection writes nothing — the Blockers
|
||||
;; #4 deadlock the m2 loop observed.
|
||||
;;
|
||||
;; er-spawn-fun requires an er-fun (Erlang-AST-shaped
|
||||
;; dict); handler IS one (created by user `fun (Req) ->
|
||||
;; route(Req, Cfg) end`). To feed req-pl as the call
|
||||
;; argument we stash it on the process record's
|
||||
;; :pending-args field — er-sched-step-alive! reads it
|
||||
;; on first step (the alternative was a host-closure-to-
|
||||
;; er-fun wrapper, which needs AST construction).
|
||||
((sx-handler
|
||||
(fn (req-dict)
|
||||
(let ((req-pl (er-request-dict-to-proplist req-dict)))
|
||||
(let ((resp-pl (er-apply-fun handler (list req-pl))))
|
||||
(er-proplist-to-dict resp-pl))))))
|
||||
(let ((proc (er-proc-new! (er-env-new))))
|
||||
(dict-set! proc :initial-fun handler)
|
||||
(dict-set! proc :pending-args (list req-pl))
|
||||
(er-sched-run-all!)
|
||||
(let ((resp-pl (er-proc-field (get proc :pid) :exit-result)))
|
||||
(er-proplist-to-dict resp-pl)))))))
|
||||
(http-listen port sx-handler))))))
|
||||
|
||||
;; httpc:request/4(Url, Method, Headers, Body) - BRIEFING-EXCEPTION:
|
||||
|
||||
Reference in New Issue
Block a user