biubiu8802 on X (tweet 2118719081872540038): behind their proxy every
update failed with "download broke off, a network problem", while the
same proxy carried ordinary downloads. Confirmed in the code: download()
retried up to 5 times with Range, but each try went through
netproxy.Dispatch over HTTP/2 again; Dispatch moves a host to HTTP/1.1
only on a TLS record error (recordError: bad record MAC and kin), and
"unexpected EOF" or a stream reset is not one. So a proxy that cuts
HTTP/2 streams part way cut every try the same way.
- netproxy: OverHTTP1(ctx) sends every request under ctx through
Dispatch's HTTP/1.1 copy (route.h1), kept through With.
BrokeOff(err) says a transfer broke off (net.Error, unexpected EOF,
HTTP/2 stream error / GOAWAY / lost connection, a reset; not a
context that ended). AgainOverHTTP1 runs a download once more over
HTTP/1.1 after such a failure.
- update: the tries after a broken one go over HTTP/1.1, and still
resume with Range from the bytes kept.
- Siblings, the other big downloads through Dispatch's client: the
masking model and pf-serve (pii.fetch, one more try over HTTP/1.1
from what is on the .part file), Bun's zip (plugin getURLFrom),
Claude Code's binary (claudecode.download) and the Grok CLI
(grokDownload) each try once more over HTTP/1.1.
- docs/subsystems/providers-accounts.md names it.
Run (mote, Go 1.26.8, at this tree, base 80ae904c2 = origin/main fetched
just before push):
- TestDownloadBrokenOverHTTP2TriesHTTP1 (httptest TLS HTTP/2 server
that resets each HTTP/2 stream after 100KB, serves HTTP/1.1 whole):
red with the update.go line taken out, all six tries over HTTP/2
("stream error: ... INTERNAL_ERROR"); green after, asked
["HTTP/2.0 ", "HTTP/1.1 bytes=102400-"].
- TestOverHTTP1EveryHost, TestAgainOverHTTP1, TestBrokeOff: green.
- go test ./internal/netproxy ./internal/update ./internal/pii
./internal/claudecode ./internal/plugin ./internal/provider: ok.
- go test ./... -count=1 -timeout 45m: 86 ok, gateway 795s and agent
303s ok; internal/gui red only on two AppKit tests already filed for
mote's macOS 27: TestMainWindowCorners/macOS_26_SDK (#3949) and
TestPanelHiddenByWailsMarksPageOutOfSight (#5322). Nothing in gui is
touched here.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet of the touched
packages clean.
Not tried: a real proxy that cuts HTTP/2 (the reporter's); the retry of
pii, Bun, Claude Code and Grok against a real host (unit-covered by
AgainOverHTTP1 only); Windows/Linux test runs.
80 lines
2.5 KiB
Go
80 lines
2.5 KiB
Go
package update
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"crypto/sha256"
|
|
"crypto/tls"
|
|
"crypto/x509"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/netproxy"
|
|
)
|
|
|
|
// biubiu8802 on X: a proxy that cuts every HTTP/2 stream part way, while
|
|
// it carries HTTP/1.1 to the same host whole. Each try of the update broke
|
|
// off the same way ("unexpected EOF"), as each went over HTTP/2 again; the
|
|
// tries after the first go over HTTP/1.1, and on from where it broke off.
|
|
func TestDownloadBrokenOverHTTP2TriesHTTP1(t *testing.T) {
|
|
quickRetries(t)
|
|
body := make([]byte, 512<<10)
|
|
for i := range body {
|
|
body[i] = byte(i * 13)
|
|
}
|
|
sum := sha256.Sum256(body)
|
|
var mu sync.Mutex
|
|
var asked []string // "proto range" of each request
|
|
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
asked = append(asked, r.Proto+" "+r.Header.Get("Range"))
|
|
mu.Unlock()
|
|
from := 0
|
|
if rg := r.Header.Get("Range"); rg != "" {
|
|
from, _ = strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(rg, "bytes="), "-"))
|
|
w.Header().Set("Content-Range", fmt.Sprintf("bytes %d-%d/%d", from, len(body)-1, len(body)))
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(body)-from))
|
|
w.WriteHeader(http.StatusPartialContent)
|
|
} else {
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(body)))
|
|
}
|
|
if r.ProtoMajor == 2 {
|
|
// the proxy cuts the stream part way: a reset
|
|
// (INTERNAL_ERROR) after the first 100KB
|
|
w.Write(body[from:min(from+100<<10, len(body))])
|
|
w.(http.Flusher).Flush()
|
|
panic(http.ErrAbortHandler)
|
|
}
|
|
w.Write(body[from:])
|
|
}))
|
|
srv.EnableHTTP2 = true
|
|
srv.StartTLS()
|
|
defer srv.Close()
|
|
pool := x509.NewCertPool()
|
|
pool.AddCert(srv.Certificate())
|
|
old := client
|
|
tr := &http.Transport{ForceAttemptHTTP2: true, TLSClientConfig: &tls.Config{RootCAs: pool}}
|
|
client = &http.Client{Transport: netproxy.Dispatch(tr)}
|
|
t.Cleanup(func() { client = old; tr.CloseIdleConnections() })
|
|
|
|
path := filepath.Join(t.TempDir(), "magpie.new")
|
|
if err := download(context.Background(), Asset{URL: srv.URL, SHA256: hex.EncodeToString(sum[:])}, path); err != nil {
|
|
t.Fatalf("download: %v (asked %q)", err, asked)
|
|
}
|
|
want := []string{"HTTP/2.0 ", "HTTP/1.1 bytes=102400-"}
|
|
if fmt.Sprint(asked) != fmt.Sprint(want) {
|
|
t.Fatalf("asked %q, want %q", asked, want)
|
|
}
|
|
if b, _ := os.ReadFile(path); !bytes.Equal(b, body) {
|
|
t.Fatalf("file has %d bytes, not the release's", len(b))
|
|
}
|
|
}
|