Commit 1024f4d
committed
Address Fable review: ctx lifetime, race, fail-closed, caps, wire masking
Correctness batch first (Fable found the module was silently broken):
- Blocker #1 (fan-out ctx dies on hook return). The framework cancels
each hook's own ctx the moment the hook returns
(hooks/hookexecution/execution.go), so a fan-out rooted in an
entrypoint hook's ctx was Done before the goroutine spawned.
Consequence: every provider call started already-cancelled, zero
segments landed, and the failure was silent (errors stayed inside
providerResult.Errs and analytics reported Success). Removed the
entrypoint hook entirely; the async holder now allocates inside
HandleProcessedAuctionHook with a Background-rooted ctx, cancelled
via defer async.cancel() in the response hook. That also fixes
finding prebid#6 (response hook stalling for its full group timeout when
processed-auction never ran) — no holder ever means the response
hook short-circuits cleanly.
- Blocker prebid#2 (data race on live BidRequest). The fan-out goroutine
read Site/Imp/Device.Geo/User.EIDs and unmarshalled User.Ext while
the auction continued to mutate the wrapper (RebuildRequest,
privacy scrubbing, other modules). deriveInputs now runs
synchronously on the caller's stack; the goroutine only sees the
tmpInputs value snapshot and never touches the BidRequest.
- Finding prebid#10 (no hooks-level test). New hooks_test.go exercises
HandleProcessedAuctionHook → HandleAuctionResponseHook through real
hookstage plumbing, including simulating the framework's per-hook
ctx cancellation. This is the test that would have caught #1 in
the first place; it fails against the pre-fix code.
Then the small independent correctness fixes:
- prebid#4 registry bare-record parse: fall back to decoding the raw
payload as PropertyRecord when the {"property": {...}} envelope
isn't found. The old code negative-cached bare records as
"not found" for 300 s, silently.
- prebid#7 per-provider request IDs: build ctxReq and idReq inside
callProvider so two colluding providers don't get the same
request_id pair for the same auction.
- prebid#8 hostile domain: cap site.domain / app.bundle at 253 chars and
restrict to `[a-z0-9._-]`. Rejects invalid keys before touching
the LRU or the registry.
Then the design/product calls user directed on:
- prebid#3 fail-closed on identity error: providerResult tracks
IdentityAttempted (URL configured AND tokens present). When
IdentityAttempted is true but the call returned no response,
mergeSegments drops all offers for that provider. A hostile or
flaky identity endpoint can no longer convert identity-gated
packages into unconditionally-served packages.
- prebid#5 cap segments + batch per-bid targeting write. New config knobs
MaxSegments (default 128) and MaxSegmentValueLen (default 256)
bound both the total segment count and each segment's length,
regardless of what a provider returns. Response-hook per-bid
targeting now builds one map from segments and writes it via a
single sjson.SetBytes per bid at ext.prebid.targeting instead of
O(bids × segments) rewrites. Provider names are also validated
in Config.validated() to prevent them from colliding with Prebid's
reserved targeting prefixes (hb_*).
- prebid#9 wire the masking config. coarseGeo now takes cfg and honors
PreserveMetro / PreserveZip / PreserveCity / LatLongPrecision
(with math.Trunc for lat/lon precision); extractIdentities honors
PreserveMobileIds (drops maid-typed tokens when masking enabled
and false) and PreserveEids (allowlist over the default set).
Deleted the now-empty masking.go — every knob is now wired
through adapter.go at input-derivation time.
Nits also addressed:
- Analytics no longer reports Success when every provider errored;
errCount from routerResult drives Status/ResultStatus explicitly.
- site.page's query and fragment components are stripped before
emission as an artifact ref — gclid / click IDs / occasional
email leak into the identity-free context path.
- Ordering test reframed: with DecorrelationMaxDelayMs > 0 the
second-to-spawn call is deterministically delayed, so HTTP arrival
order actually reflects the shuffle instead of scheduler noise.
- Panic-recovery test replaced with one that injects a panicking
RoundTripper — actually exercises the recover paths in
callProvider's inner goroutines.
- Nil-guard on payload.BidResponse in the response-hook mutation.
- Removed unused asyncRequest.err field.1 parent 004f9ca commit 1024f4d
10 files changed
Lines changed: 809 additions & 306 deletions
File tree
- modules/adcontextprotocol/tmp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
54 | 65 | | |
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
59 | 70 | | |
60 | | - | |
| 71 | + | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
| |||
70 | 81 | | |
71 | 82 | | |
72 | 83 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
39 | 45 | | |
40 | 46 | | |
41 | | - | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
70 | 76 | | |
71 | 77 | | |
72 | 78 | | |
73 | | - | |
| 79 | + | |
74 | 80 | | |
75 | 81 | | |
76 | | - | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
80 | 86 | | |
81 | | - | |
| 87 | + | |
82 | 88 | | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
88 | | - | |
89 | | - | |
90 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
91 | 116 | | |
92 | 117 | | |
93 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
94 | 131 | | |
95 | 132 | | |
96 | 133 | | |
97 | 134 | | |
98 | 135 | | |
99 | 136 | | |
100 | 137 | | |
101 | | - | |
| 138 | + | |
102 | 139 | | |
103 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
104 | 151 | | |
105 | 152 | | |
106 | 153 | | |
107 | 154 | | |
108 | 155 | | |
109 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
110 | 165 | | |
111 | 166 | | |
112 | 167 | | |
113 | 168 | | |
114 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
115 | 174 | | |
116 | 175 | | |
117 | 176 | | |
| |||
121 | 180 | | |
122 | 181 | | |
123 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
124 | 198 | | |
125 | 199 | | |
126 | 200 | | |
| |||
132 | 206 | | |
133 | 207 | | |
134 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
135 | 212 | | |
136 | 213 | | |
137 | 214 | | |
138 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
139 | 219 | | |
140 | 220 | | |
141 | 221 | | |
| |||
180 | 260 | | |
181 | 261 | | |
182 | 262 | | |
| 263 | + | |
| 264 | + | |
183 | 265 | | |
184 | 266 | | |
185 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
61 | 73 | | |
62 | 74 | | |
63 | 75 | | |
| |||
127 | 139 | | |
128 | 140 | | |
129 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
130 | 150 | | |
131 | 151 | | |
132 | 152 | | |
| |||
147 | 167 | | |
148 | 168 | | |
149 | 169 | | |
| 170 | + | |
150 | 171 | | |
151 | 172 | | |
152 | 173 | | |
153 | 174 | | |
154 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
155 | 183 | | |
156 | 184 | | |
157 | 185 | | |
| |||
181 | 209 | | |
182 | 210 | | |
183 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
184 | 221 | | |
185 | 222 | | |
186 | 223 | | |
| |||
0 commit comments