Repository navigation
fix(server): a peer forwards a write under the path it was sent to - #2245
Conversation
A nested router strips its prefix from the URI a handler sees, so a peer forwarded /v1/fluree/insert/<ledger> as /insert/<ledger>, which the transaction server answers 404. The forwarder now takes the original URI.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz nice catch, and at a design level no pushback from me. It's the same OriginalUri resolution the Raft follower forwarder has had since a8c271b2a, and it's worth saying that this has been broken for every peer forward since v4 (writes, but also push, import, export, log, show, commits, validate and pack all go through this one forward), so the first end-to-end peer-forward test is a good thing to have. The only headline note from me is that it's the second time we've fixed this in one of our two forwarders, and the two still disagree on a trailing /. I've left an optional note below about sharing one URL builder beside is_hop_by_hop, but I wouldn't hold the merge on it.
Full review below:
✅ Approve.
This is a nice small fix, @bplatz. ForwardingClient::forward took request.uri(), which the /v1/fluree nest has already stripped, and now prefers OriginalUri the way the Raft forwarder does. The one hunk covers every peer forward, since they all funnel through this function. The new test checks that the write actually landed on the transaction server (t() == 1), not just the status, and it goes red with a 404 when the fix is reverted.
Adherence to repo commitments:
- Patterns/abstractions: ✔ converges on the Raft forwarder's existing
OriginalUrihandling; the optional note is about sharing it rather than keeping two copies. - Performance (speed first, memory second): ✔ server forwarding path only: one extension lookup per forwarded request. No performance-degradation risk.
- Deployment targets: ✔ n/a —
fluree-db-serveronly (peer mode); the evidence is a server integration test, which is that host. - Testing: ✔
test_proxy_peer_forwards_a_writeingrp_proxy, which CI's workspace nextest ran green on the head; red (404) with the fix reverted. - Conventions: ✔ self-describing subject with a body that names the mechanism; clippy and fmt green.
Verified locally at branch HEAD: the new test passes; with forward.rs reverted to the merge-base it fails 404 != 200; restored, both test_proxy_peer_* tests pass; all forward call sites traced.
Approving so you can merge when ready.
| let uri = request | ||
| .extensions() | ||
| .get::<OriginalUri>() | ||
| .map_or_else(|| request.uri().clone(), |original| original.0.clone()); |
There was a problem hiding this comment.
Optional. This is more of a suggestion than a must. The Raft follower forwarder had this exact 404 and picked up the same OriginalUri resolution in a8c271b2a (fluree-raft-core/src/forward.rs:474-478), so we now have two forwarders that each rebuild the outbound URL on their own, and that's how this one stayed broken after the other was fixed.
They still differ in one small way: the Raft one trims a trailing / off the base URL (fluree-raft-core/src/forward.rs:481) and this one doesn't (format!("{}{}", self.base_url, ...) a few lines down), so a peer started with --tx-server-url http://tx:8090/ would forward to http://tx:8090//v1/fluree/.... That's pre-existing, and I've only read it off the code, not run it.
Both already share is_hop_by_hop from fluree-raft-core/src/http.rs, so maybe one outbound_url(base, &request) beside it that both forwarders call? It's about ten lines. It's minor and non-blocking, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
The Raft follower forwarder and the peer forwarder each rebuilt the outbound URL on their own, which is how the peer one kept the 404 the other had fixed. They still differed on a trailing `/` in the base URL: a peer started with `--tx-server-url http://tx:8090/` forwarded to `http://tx:8090//v1/fluree/...`. Both now call `outbound_url` beside `is_hop_by_hop`: the client's path and query, preferring axum's `OriginalUri` over the prefix-stripped URI, on the base URL without its trailing `/`.
Brings #2247, #2232, #2246, #2248, #2245, #2230, #2205, #2231, #2255, #2219, #2209, #2207, #2190, #2216, #2186, #2215, #2213, #2184, #2210, #2206, #2198, #2187, #2183, #2200, #2193, #2199, #2196 and #2145 into next. Resolutions: - Novelty: main's fact-state trim (a cutoff plus a bounded sweep) and the dictionary's coverage watermark sit on next's graph slots and per-graph OrdMaps. A commit's reification links count toward coverage. Planner stats from segment sums decline under annotations, whose link deltas only the walk counts, and otherwise carry the indexed link counts. - Stats-view identity: the index root's id reaches the snapshot through next's root decoder (`decode` takes the id, as `take_snapshot_metadata` does). `LedgerState::load_record` has a decoding-root form beside `load_decoding_root`. - Transact: #2184's parallel-relationship check runs in next's link cascade, counting the `rdf:reifies` links on the retracted edge that the transaction does not retract itself. Main's bundle `edge_reifiers` is dropped, and `subjects_with_prior_rows` and `enforce_single_target_reifiers` stay deleted. The upsert pre-check takes main's dictionary probe and bounded seek. - Query: geo search resolves the graph's POST tree once at open (pooled graphs keep their filter), an empty manifest when there is none. `branch_or_none` reads the dedicated branch, and the batched joins keep next's pooled lanes. The stats-view key hashes the root id. - Indexer: `apply_dict_novelty` and `compact_forward_streams` take the cycle's compaction budget, so the term dictionary keeps its reserved share. `Prefetched` holds `ContentBytes`. `relocalize_sorted_commit` rewrites next's 20-byte types records. - Disk cache: main's in-flight write registration, with an empty entry still read as crash debris that a write replaces. The process-wide eviction walk stays removed. - Graph import (#2232): fenced CAS and publishes, the seed carries the record's namespace and fence, 32-bit graph ids and next's loaders. An import into a graph of an existing ledger refuses triple terms and edge annotations: the splice merges no triple-term dictionary yet. - Iceberg: `create_iceberg_graph_source` goes with main (a source needs a mapping); the R2RML path keeps next's `model_instance`. - CLI: main's shared import flags without the leaflet flags; `graph import` routes through next's process-wide server routing, and `upload_source_import` serves next's `Destination`. Doc sources read a ledger through the command's open instance. - Tests: sibling ledger ids become distinct names, `genesis_ledger` is awaited, Cypher state dumps include each relationship's `rdf:reifies` link, and the graph-import arena test checks the refusal instead.
A peer forwards requests under the path they were sent to
A query peer forwards writes to the transaction server. Routes are nested under
/v1/fluree, and a nested router strips its prefix from the URI a handler sees. The forwarder sent that stripped URI, so a peer forwardedPOST /v1/fluree/insert/<ledger>asPOST /insert/<ledger>, which the transaction server answers with 404. The forwarder now takes the original URI.The same forwarder carries a peer's
import,export,logandcommitsrequests.Test:
test_proxy_peer_forwards_a_write(404 onmain).