carlos / platform Public

edge: every GOAWAY above last-stream-id is a refusal (#511 R26)

Astra's minor: x/net v0.62 aborts every stream above a GOAWAY's
last-stream-id with errClientConnGotGoAway whatever the code, except
stream 1 under an error-code GOAWAY, which gets a formatted message.
Both mean the box did not process the stream (RFC 9113 §6.8). The
comment overstated the graceful/error split, and the stream-1-only
negative test pinned x/net's message rather than the protocol. Both
messages are now matched, and TestReplicaRefusedStreamBoundary covers a
graceful and an error-code GOAWAY on stream 1 and on a later stream.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 58764118432bd3e859bd9149941bcd39c766bcaf parent 649f0cd
2 files changed, +54 −17
  • internal/edge/replica_reach_test.go +32 −6
  • internal/edge/tunnel.go +22 −11
diff --git a/internal/edge/replica_reach_test.go b/internal/edge/replica_reach_test.go
index 2276b335c..7bb01688b 100644
--- a/internal/edge/replica_reach_test.go
+++ b/internal/edge/replica_reach_test.go
@@ -1,6 +1,7 @@
package edge
import (
+ "bytes"
"io"
"net"
"net/http"
@@ -12,6 +13,7 @@ import (
"time"
"golang.org/x/net/http2"
+ "golang.org/x/net/http2/hpack"
"github.com/carlosframework/platform/internal/tunnelclient"
)
@@ -37,6 +39,9 @@ const (
framerResetInternal = "reset-internal" // RST_STREAM INTERNAL_ERROR
framerGoAwayBelow = "goaway-below" // a graceful GOAWAY whose last stream is below it
framerGoAwayError = "goaway-error" // a GOAWAY with an error code, last stream below it
+ // the first stream with a 200, a later one with a GOAWAY with an error
+ // code whose last stream is below it
+ framerGoAwayErrorLater = "goaway-error-later"
)
// replicaFramerBox replaces box's channel on hub with a framerBox and points
@@ -102,6 +107,16 @@ func replicaFramerBox(t *testing.T, hub *TunnelHub, p *replicaProber, host, box,
write(func() error { return fr.WriteGoAway(below, http2.ErrCodeNo, nil) })
case framerGoAwayError:
write(func() error { return fr.WriteGoAway(below, http2.ErrCodeProtocol, nil) })
+ case framerGoAwayErrorLater:
+ if id == 1 {
+ var block bytes.Buffer
+ hpack.NewEncoder(&block).WriteField(hpack.HeaderField{Name: ":status", Value: "200"})
+ write(func() error {
+ return fr.WriteHeaders(http2.HeadersFrameParam{StreamID: id, BlockFragment: block.Bytes(), EndStream: true, EndHeaders: true})
+ })
+ } else {
+ write(func() error { return fr.WriteGoAway(below, http2.ErrCodeProtocol, nil) })
+ }
}
}
}
@@ -306,10 +321,11 @@ func TestReplicaRefusedStreamKeepsHealthyCopy(t *testing.T) {
// real x/net ClientConn, with a frame-level box that receives the HEADERS
// (so R22's never-written proof does not apply) and then answers:
// - RST_STREAM REFUSED_STREAM: refused (RFC 9113 §8.7);
-// - a graceful GOAWAY whose last stream is below this one: refused (§6.8;
-// x/net aborts it with errGracefulGoAway's text);
-// - RST_STREAM INTERNAL_ERROR, or a GOAWAY with an error code: may have
-// reached, as any other reset.
+// - a GOAWAY whose last stream is below this one, graceful or with an
+// error code, on the first stream or a later one: refused (§6.8). x/net
+// aborts stream 1 under an error-code GOAWAY with its own message, and
+// every other case with errClientConnGotGoAway; both are matched;
+// - RST_STREAM INTERNAL_ERROR: may have reached, as any other reset.
func TestReplicaRefusedStreamBoundary(t *testing.T) {
for _, c := range []struct {
mode string
@@ -317,15 +333,25 @@ func TestReplicaRefusedStreamBoundary(t *testing.T) {
}{
{framerRefuses, reachRefused},
{framerGoAwayBelow, reachRefused},
+ {framerGoAwayError, reachRefused},
+ {framerGoAwayErrorLater, reachRefused},
{framerResetInternal, reachMaybe},
- {framerGoAwayError, reachMaybe},
} {
t.Run(c.mode, func(t *testing.T) {
hub, p, rt := replicaProxyFixture(t, func(http.ResponseWriter, *http.Request) {}, func(http.ResponseWriter, *http.Request) {})
fb := replicaFramerBox(t, hub, p, rt.Host, "box-00", c.mode)
+ heads := int32(1)
+ if c.mode == framerGoAwayErrorLater {
+ resp, reach, err := hub.replicaRoundTrip("pi/box-00", replicaDispatchRequest(t, "GET", nil))
+ if err != nil || resp.StatusCode != 200 || reach != reachMaybe {
+ t.Fatalf("the first stream: %v %v %d", resp, err, reach)
+ }
+ resp.Body.Close()
+ heads = 2
+ }
_, reach, err := hub.replicaRoundTrip("pi/box-00", replicaDispatchRequest(t, "POST", strings.NewReader("payload")))
// TestReplicaRefusedStreamBoundary
- if err == nil || reach != c.want || fb.headers.Load() != 1 {
+ if err == nil || reach != c.want || fb.headers.Load() != heads {
t.Fatalf("%s: reach %d (%v) with %d HEADERS at the box, want %d", c.mode, reach, err, fb.headers.Load(), c.want)
}
})
diff --git a/internal/edge/tunnel.go b/internal/edge/tunnel.go
index 2cea4186c..fb8f97050 100644
--- a/internal/edge/tunnel.go
+++ b/internal/edge/tunnel.go
@@ -850,32 +850,43 @@ const (
// reachRefused: the box received the stream and refused it unprocessed
// (#511 R26): RST_STREAM REFUSED_STREAM (RFC 9113 §8.7, "not processed
// in any way"), or the stream was above the last-stream-id of a
- // graceful GOAWAY (§6.8). The hub's ClientConn may have sent part of the
+ // GOAWAY (§6.8), whatever its error code. The hub's ClientConn may have sent part of the
// body, so a retry needs a fresh copy of it.
reachRefused
// reachMaybe: anything else; the box may have acted on the request.
reachMaybe
)
-// errGracefulGoAway is the message x/net v0.62.0 aborts a stream with when
-// it is above the last-stream-id of a graceful GOAWAY the box sent
-// (transport.go:611, errClientConnGotGoAway, transport_common.go:206). The
-// value is unexported, so it is matched by its text, which
-// TestReplicaRefusedStreamBoundary pins against the real ClientConn. A
-// GOAWAY with an error code aborts streams with another message, which
-// stays reachMaybe.
-const errGracefulGoAway = "http2: Transport received Server's graceful shutdown GOAWAY"
+// goAwayAbort and goAwayFirstStreamAbort are the two messages x/net
+// v0.62.0 aborts a stream with when it is above the last-stream-id of a
+// GOAWAY the box sent (ClientConn.setGoAway, transport.go:595-613): every
+// such stream gets errClientConnGotGoAway (transport_common.go:206),
+// whatever the GOAWAY's error code, except stream 1 under a GOAWAY with an
+// error code, which gets the second, formatted message. Both mean the box
+// did not process the stream (RFC 9113 §6.8). A stream at or below the
+// last-stream-id is left alone by setGoAway and ends some other way, which
+// stays reachMaybe. The values are unexported, so they are matched by
+// their text, which TestReplicaRefusedStreamBoundary pins against the real
+// ClientConn for every case: either code, stream 1 or a later one.
+const (
+ goAwayAbort = "http2: Transport received Server's graceful shutdown GOAWAY"
+ goAwayFirstStreamAbort = "http2: Transport received GOAWAY from server ErrCode:"
+)
// refusedByBox reports whether err is the box's refusal of the stream:
// x/net's client surfaces a peer's RST_STREAM as StreamError{Code} (its
// processResetStream, transport.go:2641), and itself never makes one with
-// REFUSED_STREAM; or the graceful GOAWAY abort above.
+// REFUSED_STREAM; or a GOAWAY abort above.
func refusedByBox(err error) bool {
var se http2.StreamError
if errors.As(err, &se) && se.Code == http2.ErrCodeRefusedStream {
return true
}
- return err != nil && err.Error() == errGracefulGoAway
+ if err == nil {
+ return false
+ }
+ msg := err.Error()
+ return msg == goAwayAbort || strings.HasPrefix(msg, goAwayFirstStreamAbort)
}
// replicaRoundTrip sends req down channel and reports what the hub can