From c320f75a157e199018a794c3bb490f4947ac4e9c Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Thu, 12 Jan 2023 16:32:39 +0800 Subject: [PATCH] grpc-gateway: update version to v1.11.0 The issue is caused by hand-crafted protobuf message. The runtime.errorBody defines two protobuf fields with same number. We need to upgrade the version to fix it. Otherwise, the client side won't receive any errors from server side because of panic. ``` mismatching field: runtime.errorBody.error, want runtime.errorBody.message ``` It can fix the cases PASSES="build grpcproxy" CPU=4 RACE=true ./test -run TestV3CurlLeaseRevokeNoTLS The original error is like: ``` v3_curl_lease_test.go:109: testV3CurlLeaseRevoke: prefix (/v3) endpoint (/kv/lease/revoke): error (read /dev/ptmx: input/output error (expected "etcdserver: requested lease not found", got ["curl: (52) Empty reply from server\r\n"])), wanted etcdserver: requested lease not found v3_curl_lease_test.go:109: testV3CurlLeaseRevoke: prefix (/v3beta) endpoint (/kv/lease/revoke): error (read /dev/ptmx: input/output error (expected "etcdserver: requested lease not found", got ["curl: (52) Empty reply from server\r\n"])), wanted etcdserver: requested lease not found ``` The `Empty reply from server` is caused by panic and server recover it but it doesn't have chance to reply to client. Signed-off-by: Wei Fu --- go.mod | 2 +- go.sum | 4 ++-- tests/e2e/v3_curl_test.go | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index f7c1eb11400..aa9eb3290b2 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/google/uuid v1.0.0 github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 - github.com/grpc-ecosystem/grpc-gateway v1.9.5 + github.com/grpc-ecosystem/grpc-gateway v1.11.0 github.com/jonboulle/clockwork v0.1.0 github.com/json-iterator/go v1.1.11 github.com/modern-go/reflect2 v1.0.1 diff --git a/go.sum b/go.sum index a75629cb5e9..eaed1c47588 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.5 h1:UImYN5qQ8tuGpGE16ZmjvcTtTw24zw1QAp/SlnNrZhI= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/grpc-ecosystem/grpc-gateway v1.11.0 h1:aT5ISUniaOTErogCQ+4pGoYNBB6rm6Fq3g1v8QwYGas= +github.com/grpc-ecosystem/grpc-gateway v1.11.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= diff --git a/tests/e2e/v3_curl_test.go b/tests/e2e/v3_curl_test.go index b2ddb7f0f6e..18756041b37 100644 --- a/tests/e2e/v3_curl_test.go +++ b/tests/e2e/v3_curl_test.go @@ -343,7 +343,12 @@ func testV3CurlProclaimMissiongLeaderKey(cx ctlCtx) { if err = cURLPost(cx.epc, cURLReq{ endpoint: path.Join(cx.apiPrefix, "/election/proclaim"), value: string(pdata), - expected: `{"error":"\"leader\" field must be provided","message":"\"leader\" field must be provided","code":2}`, + // NOTE: The order of json fields is aligned with the runtime.errorBody + // + // REF: + // 1. https://github.com/grpc-ecosystem/grpc-gateway/blob/v1.11.0/runtime/errors.go#L73 + // 2. https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto#L82 + expected: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`, }); err != nil { cx.t.Fatalf("failed post proclaim request (%s) (%v)", cx.apiPrefix, err) } @@ -359,7 +364,12 @@ func testV3CurlResignMissiongLeaderKey(cx ctlCtx) { if err := cURLPost(cx.epc, cURLReq{ endpoint: path.Join(cx.apiPrefix, "/election/resign"), value: `{}`, - expected: `{"error":"\"leader\" field must be provided","message":"\"leader\" field must be provided","code":2}`, + // NOTE: The order of json fields is aligned with the runtime.errorBody + // + // REF: + // 1. https://github.com/grpc-ecosystem/grpc-gateway/blob/v1.11.0/runtime/errors.go#L73 + // 2. https://github.com/grpc/grpc/blob/master/src/proto/grpc/status/status.proto#L82 + expected: `{"error":"\"leader\" field must be provided","code":2,"message":"\"leader\" field must be provided"}`, }); err != nil { cx.t.Fatalf("failed post resign request (%s) (%v)", cx.apiPrefix, err) }