Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API returns a stream stops streaming after 8 seconds when accessed through grpc-gateway using HTTP #204

Open
sloppycoder opened this issue Oct 9, 2019 · 0 comments

Comments

@sloppycoder
Copy link

I'm stumped by this problem, please help.

I used grapi to create a server skeleton, then implemented an API that returns a stream.

# proto file
rpc GetTopAccounts (GetTopAccountRequest) returns (stream Account) {

# implementation
for {
for _, acc := range accounts {
		err = svr.Send(acc)
		if err != nil {
			log.Printf("error streaming %+v", err)
			return nil
		}
	}

	log.Printf("iteration %d", i)
	time.Sleep(1000 * time.Millisecond)
}

When calling this API with golang gRPC client, things work fine. However, if I use curl to access the same API using HTTP, the response will stop streaming after exactly 8 seconds.

Here is my code repo
To run it:

go run ./cmd/server

#open another window

curl http://localhost:3100/top/10
...
{"result":{"account_id":"123"}}
{"result":{"account_id":"123"}}
{"result":{"account_id":"123"}}
# after exactly 8 seconds
curl: (18) transfer closed with outstanding read data remaining

the server prints this in console
2019/10/09 21:41:11 iteration 19
2019/10/09 21:41:11 error streaming rpc error: code = Canceled desc = context canceled

Meanwhile, running the gRPC client calling the same API can does not exhibit this problem

go run ./cmd/client
...
streams forever
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant