Grpc-web: Error on helloworld example

Created on 18 Nov 2018  路  7Comments  路  Source: grpc/grpc-web

Hi!

I just try to run the hello world example to try this project but I'm facing a upstream connect error or disconnect/reset before headers error when I try to fetch http://localhost:8081/ in my browser.

The code of my helloworld project is identical to those you give in the README.md (I ended up copying/plasting files). The compilation of the protoc-gen-grpc-web and the generation with protoc are well done too.

The only issue happens when I try to run the envoy image with this command: docker run -d -p 8080:8080 --network=host helloworld/envoy. I have:

  • this warning from Docker: WARNING: Published ports are discarded when using host network mode
  • this error in my browser: Http response at 400 or 500 level.

So I tried without the host network (like this: docker run -d -p 8080:8080 helloworld/envoy) and it's a bit better: no more Docker warning and a 200 on the http://localhost:8080/helloworld.Greeter/SayHello but I have this error now: upstream connect error or disconnect/reset before headers.

Also, when I watch the /clusters it seems that the greeter_service::[::]:0::cx_connect_fail is incremented on each try. So it seems to be a connection problem.

Does someone have an idea? Thanks a lot! :)

Most helpful comment

Thanks @stanley-cheung for your quick answer!
Indeed, I'm using MacOs. Your advice was really helpful, thanks!

In order to make it work, I created a docker compose file.
I think it could be a good idea to include it in the helloworld guide in order to reduce the friction during the onboarding of new users. What do you think?

Here is the changes that I have made:

docker-compose.yaml

Note that link is a legacy feature so I rather chose a network. Can you confirm that it will work on other OS (Linux, Windows, etc.)?

version: '3'

services:
  envoy:
    build:
      context: .
      dockerfile: envoy.Dockerfile
    ports:
      - '8080:8080'
      - '9901:9901'
    networks:
      - server-net
  server:
    build:
      context: .
      dockerfile: server.Dockerfile
    ports:
      - '9090:9090'
    networks:
      - server-net

networks:
  server-net:

server.Dockerfile

FROM node

WORKDIR /helloworld

COPY ./package.json ./package.json
RUN npm install

COPY ./helloworld.proto ./helloworld.proto
COPY ./server.js ./server.js

CMD node ./server.js

envoy.yaml:

  clusters:
  - name: greeter_service
    connect_timeout: 0.25s
    type: logical_dns
    http2_protocol_options: {}
    lb_policy: round_robin
-    hosts: [{ socket_address: { address: localhost, port_value: 9090 }}]
+    hosts: [{ socket_address: { address: server, port_value: 9090 }}]

Tell me if you are interested by these changes, I could make a PR. :)

All 7 comments

Are you using Mac? --network=host may not work in Mac. You might have to use the --link node-server:node-server flag to start the Envoy server, add --name node-server when starting the Node backend server, and use node-server when referencing the backend address in the envoy.yaml.

Thanks @stanley-cheung for your quick answer!
Indeed, I'm using MacOs. Your advice was really helpful, thanks!

In order to make it work, I created a docker compose file.
I think it could be a good idea to include it in the helloworld guide in order to reduce the friction during the onboarding of new users. What do you think?

Here is the changes that I have made:

docker-compose.yaml

Note that link is a legacy feature so I rather chose a network. Can you confirm that it will work on other OS (Linux, Windows, etc.)?

version: '3'

services:
  envoy:
    build:
      context: .
      dockerfile: envoy.Dockerfile
    ports:
      - '8080:8080'
      - '9901:9901'
    networks:
      - server-net
  server:
    build:
      context: .
      dockerfile: server.Dockerfile
    ports:
      - '9090:9090'
    networks:
      - server-net

networks:
  server-net:

server.Dockerfile

FROM node

WORKDIR /helloworld

COPY ./package.json ./package.json
RUN npm install

COPY ./helloworld.proto ./helloworld.proto
COPY ./server.js ./server.js

CMD node ./server.js

envoy.yaml:

  clusters:
  - name: greeter_service
    connect_timeout: 0.25s
    type: logical_dns
    http2_protocol_options: {}
    lb_policy: round_robin
-    hosts: [{ socket_address: { address: localhost, port_value: 9090 }}]
+    hosts: [{ socket_address: { address: server, port_value: 9090 }}]

Tell me if you are interested by these changes, I could make a PR. :)

@QuentinBrosse Your docker-compose works, tested on Windows 10, Docker 18.06.1-ce-win73 (19507). Thanks so much!

Docker-compose works on Fedora 29, but still have the same error: 14, upstream connect error or disconnect/reset before headers. Copy/Pasted code from Hello World example. Kinda Envoy can't reach server?

Yes, the 14, upstream connect error or disconnect/reset before headers message means that envoy can't establish the connection to the target (cluster).

issue #436 helped me if anyone in the future isn't using docker-compose.yaml

just to keep this up-to-date, using docker-compose it doesn't require a dedicated network as in above example. All that's required is the correct socket_address in the envoy.yaml cluster configuration, being the name and port of the serving service, i.e. "server" in above example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smnbbrv picture smnbbrv  路  4Comments

rwlincoln picture rwlincoln  路  6Comments

barrymichaeldoyle picture barrymichaeldoyle  路  4Comments

ivan-sysoi picture ivan-sysoi  路  5Comments

dv29 picture dv29  路  6Comments