etcd icon indicating copy to clipboard operation
etcd copied to clipboard

Strictly define how JSONs are separated in GRPC gateway

Open socketpair opened this issue 4 years ago • 23 comments

I use GRPC gateway to access etcd watching functionality. Namely, https://github.com/etcd-io/etcd/blob/master/Documentation/dev-guide/api_grpc_gateway.md#watch-keys .

But I don't have any specifications on how should I separate JSONs in the response stream since it is not documented anywhere.

Basically I have 3 ways:

  1. HTTP chunk = message This fails at least in Fedora 31 on high load because sometimes bare newline \n appears as a separate chunk. In order to fix you probably should first concatenate JSON with \n before calling to Write(). Also, intermediate proxies may re-chunk stream.

  2. Messages are separated using strictly one newline. It is not documented as well, and comment in GRPC gateway states that newline is added just to simplify debugging. Somewhere in the net, I found that other software uses a double newline for that purpose (allow to divide messages containing formatted JSON). Currently, I choose this way.

  3. Use JSON finite state machine to detect end of a message. This way will work in any case, but technically this requires additional libraries for the majority of programming languages.

So, Please strictly document exact behavior (protocol) which should be considered for implementing JSON stream parser.

Original issue: https://github.com/grpc-ecosystem/grpc-gateway/issues/1086

socketpair avatar Nov 19 '19 16:11 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 06 '20 19:04 stale[bot]

Hay! It's still actual

socketpair avatar Apr 06 '20 22:04 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 05 '20 23:07 stale[bot]

BUMP. Still actual.

socketpair avatar Jul 06 '20 03:07 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 04 '20 04:10 stale[bot]

It is still actual!

socketpair avatar Oct 04 '20 14:10 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 02 '21 16:01 stale[bot]

No, it's not stale

socketpair avatar Jan 02 '21 18:01 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 03 '21 17:04 stale[bot]

No, it's not stale

socketpair avatar Apr 04 '21 03:04 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 03 '21 05:07 stale[bot]

It's actual

socketpair avatar Jul 03 '21 05:07 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 01 '21 06:10 stale[bot]

Still actual

socketpair avatar Oct 03 '21 09:10 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jan 01 '22 13:01 stale[bot]

Still

socketpair avatar Jan 01 '22 19:01 socketpair

We encountered the same problem, as there is no clear way to split messages, resulting in the client not being able to handle receiving partial messages or multiple messages in one HTTP chunk when ETCD is proxied by an HTTP server like nginx.

nic-6443 avatar Feb 27 '22 08:02 nic-6443

Special attention needs to be paid to ETCD v3.3.0, because of a bug in grpc-gateway v1.3.0(ETCD v3.3.0 depended on), the way of using newlines as separators will fail. See:

  • https://github.com/grpc-ecosystem/grpc-gateway/issues/495
  • https://github.com/grpc-ecosystem/grpc-gateway/pull/479

nic-6443 avatar Feb 27 '22 09:02 nic-6443

Happily I switched to websocket transport.

socketpair avatar Feb 27 '22 20:02 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 12 '22 23:06 stale[bot]

Still actual.

socketpair avatar Jun 13 '22 15:06 socketpair

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '22 02:09 stale[bot]

Bump

socketpair avatar Sep 21 '22 05:09 socketpair