Repository navigation
Conversation
…loses the connection Both preview proxies run the request in HTTP/1 full duplex, so the server no longer closes the request body under the Transport at the reply's header write. The body handed to ReverseProxy has a Close that only stops later reads, so the proxy's deferred close does not wait for the rest of the upload before the reply ends. The upstream's early reply (ModifyResponse) and the proxy's own error reply (ErrorHandler) carry Connection: close while the upload is still running, so that connection is not reused. The Transport to the guest waits up to one second for 100 Continue on a request that carries Expect: 100-continue. A guest that refuses such a request without reading the body closes at once; without the wait the proxy kept writing the upload to that closed connection and the refusal could be cut. Fixes #683
…pen; the full duplex call goes net/http reads the full duplex flag in one place, after the check that a reply with Connection: close already fails, so the call had no effect. The helper only wraps the request body now and is named for that. The Expect sentence in the docs holds for a refusal within one second.
…efusal sent without Connection: close With ExpectContinueTimeout set, a guest that refused an Expect upload without Connection: close got the body anyway; the closed expect reader made the write loop drop the guest connection, cut the reply and stall the client connection. The two "refused" subtests pinned that line and go with it.
|
Closing without merge. Review found a second regression against main on this head, so main stays as it is and #683 stays open. What the two heads showed:
The constraint any next design has to meet: once the reply is relayed while the upload is still relayed, a read of the request body can be in flight when the handler returns. Waiting for it brings back a mutual wait with a client that stops sending at the status (a chunked reply then never gets its last chunk); not waiting gives the hold above. Ending that read needs a deliberate abort, and its side effects on the server's own drain have to be measured in every cell: the stop-sending client, chunked and declared-length uploads, Follow-ups: #689 (a failed write of the upload ends the read of the reply), #690 (an |
Fixes #683.
What
The preview proxies (
proxyLocalandforwardinsandboxd/server/preview.go) cut a reply when the guest app answered before the browser had sent the whole request body. A reply written before the node has read the request body to its end now reaches the browser whole and carriesConnection: close; the node closes that connection after it. A request with no body, or whose body the node had read to its end before the reply, keeps its connection.Two rules:
ModifyResponse) and the node's own error reply (ErrorHandler) setConnection: closewhile the upload has not reached its end. Go's server closes the request body at the reply's header write unless the reply closes the connection; that close is what cut the Transport's read on main. With the header the server leaves the body alone, and the next request never meets the unread upload because there is no next request on that connection.ReverseProxyis a wrapper whoseCloseonly stops later reads.ReverseProxyand the Transport both close the request body before the reply is complete; the real body's close waits for the rest of the upload, while a chunked reply's last chunk is written only after the handler returns, so a client that stops sending at the status and the handler would wait on each other.The guest Transport is unchanged.
serve's own early answers (403, 502 for a wrong owner) are written before the proxy and are unchanged.Production lines: +47 -0 in
preview.go. Tests: +357. Docs: the "Early replies" bullet indocs/deploy.md.The branch has three commits; the second and third are review rounds. The first carried an
EnableFullDuplexcall and anExpectContinueTimeouton the guest Transport. The call had no effect (net/http reads the flag in one place, after the check a reply withConnection: closealready fails). The timeout broke a guest that refuses anExpectupload withoutConnection: close: cut reply, stalled connection, and through a forward hop two nodes waiting on each other. Both are gone.Tests
All drive a real
http.Serverover TCP. New inpreview_test.go:TestPreviewRelaysAWholeReplyWhenTheGuestAnswersBeforeTheUploadEnds(on the owner, through a forward hop)Connection: closeTestPreviewGivesAClientThatStopsSendingAtAnEarlyChunkedAnswerTheWholeReplyTestPreviewRelaysAnExpectContinueUploadTheGuestReads(on the owner, through a forward hop)Expect: 100-continueupload the guest reads gets100 Continue, then 200, and keeps the connectionTestPreviewConnectionServesTheNextRequestAfterAFullySentUpload(declared length, chunked)TestPreview502BeforeTheUploadEndsAnnouncesTheClose(upload in progress, no body, upload in progress through a forward hop)Connection: closeonly while an upload is in progressTestPreviewGivesAPoolingClientTheWholeEarlyRefusalAndItsNextRequesthttp.Clientreads the whole early 403 and its next request succeedsTestPreviewRelaysAnUpgradedConnectionBothWaysEach rule fails a test when removed:
preview.gobrowser read 40960 of 262144 reply bytes, err unexpected EOF); the two "upload in progress" 502 rows time out, the 502 does not arrive while the client holds the rest of its upload; the pooling client gets a cut 403ModifyResponsesetters removedClosepassed to the real bodycloseIfUploadingremoved from oneErrorHandlerRuns of
-run TestPreviewwith-raceon the final head: 30 of 30 on macOS, 20 of 20 in a Linux container.Cases walked
Content-Lengthor chunkedConnection: close, connection closed after itContent-LengthConnection: closeContent-LengthEvery exit of
ReverseProxy.ServeHTTPthat writes a final reply passes one of the two hooks; interim (1xx) replies do not, and they do not end the request.One case is worse than main
An
Expect: 100-continueupload with at most 256 KiB still to send, refused by a guest that closes its connection without reading the body, with a reply of tens of KiB. Linux, Go guest, raw client:-race: 1 of 150)-race: 68 of 150)Cause: when a write of the upload to the guest fails, Go's Transport closes the request body and then the guest connection, which ends the read of the reply. On main that close of the request body is the real one and reads up to 256 KiB of the upload first; the delay happens to let the reply finish. The wrapper's
Closereturns at once. With more than 256 KiB left main's close gives up at once too, and the two match. WithoutExpectthe reply is copied before the write fails, and this change is better than main (see the limits below).Who can reach it: a client that sends
Expect: 100-continueon a body of at most 256 KiB. Browsers do not sendExpect. curl 8.7.1 sends it only above 1 MiB (measured: 1048576 bytes no, 1048577 bytes yes, POST and PUT), where the two arms match. Go's client sends it only when the caller sets the header. Other clients were not checked.The root cause is the same for every row where a guest closes without reading, on both arms: a failed write of the upload must not end the read of the reply. That is a change to the guest connection, with its own review, and is recorded as #689.
Limits, stated in docs/deploy.md
Main does the same or worse in each.
Content-Lengthis still unsent, the node closes it after the reply instead.Expect, Linux, 100 runs, a 256 KiB reply to a 1 MiB upload: 94 cut on main, 22 to 34 with this change; a 4-byte reply: 0 on both.Kept without code:
Expect: 100-continue, receives100 Continueand then sends nothing gets no reply until it sends or closes. A client must send its body after a100 Continue. Main does the same.Connection: closeon the 101. No known client sends a body with an upgrade and no known server answers 101 before reading it.Hot path
Not on the claim path. Per preview request: the wrapper (24 bytes) and the two closures that capture it, and one atomic load per body read.
Gates
On this branch (main f23328d plus these commits):
golangci-lint0 issues in all five modules on linux and darwin,aslclean,go test -race ./...green on darwin and in a linux container. Go comment lines added: 0.Not run on hardware or through a real browser behind a TLS proxy. The measurements above use loopback TCP guests; in production the guest connection is a relayed stream, where a guest that closed ends the stream after its reply, and a later write of the upload fails the same way.