grapi icon indicating copy to clipboard operation
grapi copied to clipboard

"Connection reset by peer" when sending PATCH request over HTTP if GRPC & Gateway are on same addr

Open werdnum opened this issue 4 years ago • 0 comments

When I have an endpoint that uses the PATCH method, I can't send HTTP requests to that endpoint

$ curl -vvv -X PATCH http://127.0.0.1:3001/api/tasks/4 -d '{...}'
*   Trying 127.0.0.1:3001...
* Connected to 127.0.0.1 (127.0.0.1) port 3001 (#0)
> PATCH /api/tasks/4 HTTP/1.1
> Host: 127.0.0.1:3001
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 72
> Content-Type: application/x-www-form-urlencoded
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

Other HTTP methods work fine.

This appears to be because grapiserver uses cmux to multiplex GRPC and HTTP on the same address:

https://github.com/izumin5210/grapi/blob/cf43ca2d33c2d5e3fca8bc6142eca7c706e650b7/pkg/grapiserver/cmux.go#L36

... and uses cmux's HTTP1Fast() matcher, which does not recognize the PATCH method:

https://github.com/soheilhy/cmux/blob/v0.1.5/matchers.go#L46-L64

With employer approval, I'll send a pull request to pass "PATCH" to the call to HTTP1Fast() in grapiserver/cmux.go.

Workaround: when I use a different addr for GRPC and HTTP, everything works fine.

werdnum avatar Oct 25 '21 21:10 werdnum