Commit Graph
56 Commits
Author SHA1 Message Date
Muki Kiboigo ffcdcc6e09 add optional ctx to runNextTick 2026-06-05 07:25:29 -07:00
Adrià Arrufat ee21138bde fix: drop orphaned deferred contexts on frame teardown
A fetch() deferred behind a parser-blocking script keeps a DeferredContext
in the DeferringLayer whose forward.ctx points at the Fetch struct, which
lives in a page/session arena. If the transfer completes while deferred,
it is deinited and unlinked from the frame owner, so abortTransfers ->
abortOwner can't reach the now-orphaned context. It lingers in the active
list, and when the page is torn down its Fetch arena is freed; a later
flushFrame (e.g. the next page's parser-blocking script popping) replays
the buffered header callback into the freed Fetch -> use-after-free.

Add DeferringLayer.cancelFrame to drop these orphaned (terminal) contexts
during Frame.abortTransfers. Non-terminal contexts still have a live
transfer that cleans them up through its own callback path, so they are
left alone.
2026-06-05 09:47:15 +02:00
Karl Seguin 720e610542 Merge pull request #2625 from lightpanda-io/deferring_layer_error_handling
DeferringLayer correctly handle header stop/errors
2026-06-03 20:57:36 +08:00
Karl Seguin 205865f96c DeferringLayer correctly handle header stop/errors
When forwardHeader signals not to proceed, fire() should stop.

This is the direct fix to https://github.com/lightpanda-io/browser/issues/2622
2026-06-03 18:13:32 +08:00
Karl Seguin 20555150dd Fix two issues with DeferringLayer
The first is that it can outlive the Transfer and thus has to dupe anything
it'll use (e.g. the frame_id off the request).

The second is that flushFrame is reentrant (flushFrame -> fire -> flushFrame)
and that results in the active list and list pointers becoming invalid.
2026-06-03 17:31:40 +08:00
Karl Seguin f7a32c05a8 Improve / fix InterceptLayer.intercepted count tracking
The intercept state is currently split and hard to keep consistent and even
just reason about. InterceptLayer keeps the `intercepted` count, but CDP's
`BrowserContext` has its intercepted lookup. This isn't a problem per se, but
you BrowserContext.deinit tries to decrement `InterceptLayer.intercepted` which
is only safe if we can guarantee that the two are in sync. Which we can't.

This commit simplifies the upkeep of `InterceptLayer.intercepted` and uses the
Transfer's state on unpark/deinit to decrement it. The CDP layer no longer
cares about / has to maintain the count.

Driven by this crash report:

BrowserContext.deinit.intercepted
---
value: 0
/home/runner/work/browser/browser/src/lightpanda.zig:279:25: 0x2871842 in deinit (lightpanda)
/home/runner/work/browser/browser/src/cdp/CDP.zig:127:18: 0x28c3f45 in deinit (lightpanda)
/home/runner/work/browser/browser/src/Server.zig:186:21: 0x2827997 in handleConnection (lightpanda)
/home/runner/work/_temp/6dc322a8-c74f-4990-9660-4cc6dcfb9352/zig-x86_64-linux-0.15.2/lib/std/Thread.zig:509:13: 0x269c233 in entryFn (lightpanda)
???:?:?: 0x7fce7ccabd57 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7fce7ccabd57` was not available, trace may be incomplete

on 1.0.0-nightly.6542+94ba0791
2026-06-03 08:24:47 +08:00
Karl Seguin 1895d8f58d Merge pull request #2329 from lightpanda-io/deferred-layer
Deferred Layer
2026-06-02 12:43:06 +08:00
Karl Seguin e333e458b1 Merge pull request #2597 from lightpanda-io/remove_unused_imports
remove unused imports
2026-06-02 06:24:30 +08:00
Karl Seguin 37a846d91d remove unused imports 2026-06-01 22:42:39 +08:00
Muki Kiboigo 2f1362ac19 remove missing queue panic on RobotsLayer 2026-06-01 06:57:14 -07:00
Muki Kiboigo 5b4b978347 minor cleanup of DeferringLayer 2026-06-01 06:23:43 -07:00
Muki Kiboigo 51d8c8e8d8 prevent double frees on shutdown with DeferredContext 2026-06-01 06:23:43 -07:00
Muki Kiboigo 444884fb81 remove unneeded flushUnblocked 2026-06-01 06:23:42 -07:00
Muki Kiboigo 342ce9b1d9 firePartial should always have a stable response 2026-06-01 06:23:42 -07:00
Muki Kiboigo 673403f950 properly flush frame after syncRequest eval 2026-06-01 06:23:42 -07:00
Muki Kiboigo 9ab82d2761 add DeferringLayer 2026-06-01 06:23:40 -07:00
Muki Kiboigo a4c535370b add optional Abort handler to runNextTick 2026-05-25 11:05:11 -07:00
Muki Kiboigo 00ccb5ed52 NextTickNode is owned by Transfer 2026-05-25 10:52:51 -07:00
Muki Kiboigo f4de603cf5 properly deinit transfer on runNextTick 2026-05-25 10:09:53 -07:00
Muki Kiboigo 766e163ef1 properly handle cancellation of next tick events 2026-05-25 10:06:50 -07:00
Muki Kiboigo a295a7a21a various changes to properly track next ticked transfers 2026-05-25 10:06:50 -07:00
Muki Kiboigo cd5e5ece40 serve from cache on next client tick 2026-05-25 10:06:49 -07:00
Karl Seguin 1cdd2bb324 Cleanup Transfer flag
Replaces 4 boolean flags with a state. Makes it easier to figure out what the
state of the transfer is, and removes the possibility of inconsistent flags
.e.g queued + loop_owned.

loop_owned -> state != .created
_queued -> state == .queued
_perform -> state == .completing
aborted -> state == .aborted
2026-05-20 20:37:21 +08:00
Karl Seguin a5162bea8f Cleanup HttpClient.Transfer
This is just moving fields around. The end result is that there's a
`transfer.req` and a `transfer.res`.

On the Request side, we use to have a nested `params: RequestParam` resulting
in a lot of `transfer.req.params.url`. This is now `transfer.req.url`. On the
Response side, we had the exact opposite: response fields splattered directly
in the transfer, `transfer.response_header`. This is now `transfer.res.header`.

There is now an HttpClient.Response, which is the actual final response (which
could be for a transfer or something else, e.g the cache). And an
HttpClient.Transfer.Response which captures the inflight response data (and is
one of the polymorphic variants of the HttpClient.Response). Probably still not
ideal, but I'm not sure how to make it cleaner, and even if this is just an
intermediary step, I consider it an small win.
2026-05-15 12:55:47 +08:00
Muki Kiboigo 940976b6a7 properly disable cache on Network.setCacheDisabled 2026-05-14 09:03:51 -07:00
Muki Kiboigo ac863c7e2b add Network.requestServedFromCache 2026-05-13 21:47:47 -07:00
Muki Kiboigo 4a45b4d866 fix crash on robots.txt request fufilled immediately 2026-05-12 21:50:05 -07:00
Karl Seguin 50b126b402 fix cachelayer hit path 2026-05-13 07:14:44 +08:00
Karl Seguin 5e0976bbd6 fix use-after-free on robotslayer shutdown 2026-05-12 19:26:24 +08:00
Karl Seguin 82a4fc752b HttpClient Improvements
1 - Track owner of a request (for simpler / more accurate abort (TBD))

2 - Create Transfer upfront, make everything work on Transfer (not Request)
    This helps remove ambiguity about cleanup and simplifies layers. For example
    Robots request is just another normal request, not a special case. This gives
    everything a stable address (the *Transfer which can be looked up by id)
2026-05-12 19:26:24 +08:00
Adrià Arrufat eab9ae0243 RobotsLayer: use managed ArrayList 2026-05-04 08:01:22 +02:00
Muki Kiboigo e8c9acd310 fix request arena leak on CacheLayer hit 2026-04-28 09:48:23 -07:00
Muki Kiboigo 1ab445843c better arena management in Robots Layer and Context 2026-04-28 07:01:43 -07:00
Muki Kiboigo 1370f6805b add a note about cdp callback cb 2026-04-28 07:01:42 -07:00
Muki Kiboigo 3fe774fbfb pass error all the way up to Layer chain to clean 2026-04-28 07:01:42 -07:00
Muki Kiboigo 4de1dc5424 properly call error callback in InterceptionLayer 2026-04-28 07:01:42 -07:00
Muki Kiboigo 83b047e66a assert that intercepted isn't 0 before decrementing 2026-04-28 07:01:42 -07:00
Muki Kiboigo c719a522b8 use lightpanda module log in layers 2026-04-28 07:01:42 -07:00
Muki Kiboigo 152a792c18 use Request Arena in RobotsLayer 2026-04-28 07:01:41 -07:00
Muki Kiboigo e56036fb50 use Request Arena in CacheLayer 2026-04-28 07:01:41 -07:00
Muki Kiboigo fc702794c2 use Request Arena in WebBotAuthLayer 2026-04-28 07:01:41 -07:00
Muki Kiboigo d14b75d93b use Request arnea in InterceptionLayer 2026-04-28 07:01:41 -07:00
Muki Kiboigo bb9e238f6c Requests now use arenas from the arena pool 2026-04-28 07:01:41 -07:00
Muki Kiboigo 175c2cc288 ensure robots params have arena and request id 2026-04-28 07:01:41 -07:00
Muki Kiboigo 87eec578aa use arena pool in InterceptionLayer 2026-04-28 07:01:41 -07:00
Muki Kiboigo ca08f0c56d remove blocking from RequestParams 2026-04-28 07:01:40 -07:00
Muki Kiboigo 3db3281e8e working authentication with InterceptionLayer 2026-04-28 07:01:40 -07:00
Muki Kiboigo d0b421b085 partial auth challenge support 2026-04-28 07:01:40 -07:00
Muki Kiboigo dddd0dfb90 fix request id mismatch on cdp 2026-04-28 07:01:40 -07:00
Muki Kiboigo 0d50f706db more fixing of hanging in cdp interception 2026-04-28 07:01:40 -07:00