rproxy: the body wrappers hold only what they call #431

Open
opened 2026-11-19 17:12:20 +01:00 by clawbot · 1 comment
Collaborator

From the architecture review, "Inside rproxy", under "The body wrappers hold the whole request": #283 (comment). Approved for building: #283 (comment). The code was read at 809d266 on next. Line numbers are that commit's.

What is there

  • requestBody and responseBody in internal/rproxy/bodies.go each hold rq *request. Their Read is called on other goroutines than the handler's: the transport's, and the one that copies the app's answer.
  • requestBody uses the pointer for one call: b.rq.refuse(http.StatusRequestEntityTooLarge) (line 71).
  • responseBody uses it for three things: b.rq.responseReceived() (line 103), b.rq.refuse(http.StatusBadGateway) (lines 105 and 111), and b.rq.in.Context() (line 108).

Why it matters

With the whole request in reach, the type does not say what another goroutine may touch. refuse is safe there because refused is atomic. The next field someone reads through b.rq may not be.

What changes

Each wrapper holds only what it calls:

  • requestBody gets a refuse func(status int);
  • responseBody gets that, a function to call once the app's whole answer has arrived, and the request's context.

Neither holds a *request.

What stays

  • request goes on reading the fields of its own requestBody (held, waiting, received, bytes, mu, stopped). That direction is not the finding.
  • upgradedConn and responseWriter are untouched.

Done when

  • neither wrapper has a field of type *request;
  • behaviour is unchanged: every existing test passes with no assertion changed;
  • make check passes;
  • the PR body lists every new field name.

Model: fable-5-2

From the architecture review, "Inside `rproxy`", under "The body wrappers hold the whole request": https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-173849. Approved for building: https://git.eeqj.de/sneak/smallwebwaf/issues/283#issuecomment-183550. The code was read at `809d266` on `next`. Line numbers are that commit's. ### What is there - `requestBody` and `responseBody` in `internal/rproxy/bodies.go` each hold `rq *request`. Their `Read` is called on other goroutines than the handler's: the transport's, and the one that copies the app's answer. - `requestBody` uses the pointer for one call: `b.rq.refuse(http.StatusRequestEntityTooLarge)` (line 71). - `responseBody` uses it for three things: `b.rq.responseReceived()` (line 103), `b.rq.refuse(http.StatusBadGateway)` (lines 105 and 111), and `b.rq.in.Context()` (line 108). ### Why it matters With the whole request in reach, the type does not say what another goroutine may touch. `refuse` is safe there because `refused` is atomic. The next field someone reads through `b.rq` may not be. ### What changes Each wrapper holds only what it calls: - `requestBody` gets a `refuse func(status int)`; - `responseBody` gets that, a function to call once the app's whole answer has arrived, and the request's context. Neither holds a `*request`. ### What stays - `request` goes on reading the fields of its own `requestBody` (`held`, `waiting`, `received`, `bytes`, `mu`, `stopped`). That direction is not the finding. - `upgradedConn` and `responseWriter` are untouched. ### Done when - neither wrapper has a field of type `*request`; - behaviour is unchanged: every existing test passes with no assertion changed; - `make check` passes; - the PR body lists every new field name. Model: fable-5-2
clawbot self-assigned this 2026-11-19 17:12:20 +01:00
Author
Collaborator

PR: #457, branch issue-431-body-wrapper-fields. Both body wrappers now hold callbacks for what they call instead of the *request, plus the request's context for responseBody.

Model: opus-5-5

PR: https://git.eeqj.de/sneak/smallwebwaf/pulls/457, branch `issue-431-body-wrapper-fields`. Both body wrappers now hold callbacks for what they call instead of the `*request`, plus the request's context for `responseBody`. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/smallwebwaf#431