概要
現在、勉強の為にgRPC+Go+React+TypeScriptを用いた個人開発を行っています。
ReactとGoの間にはEnvoy Proxyを置いています。
gRPCは初めてということもあり、新規会員登録機能においてgRPCの接続テストを行っています。
具体的には、新規会員登録機能にアクセスするとgRPCでリクエストを送り、それに対するレスポンスをReact側でconsole.log
するというものです。
しかし、そこで下記の内容のエラーが発生しました。
自分なりに色々調べてみましたが、解決せず…。
このままだと一向に次のフェーズに進めそうにないです…。
どなたか解決方法のご教授お願い致します。
エラーの内容
Error: upstream connect error or disconnect/reset before headers. reset reason: connection termination
該当のソースコード
docker
1// client 2 3FROM node:latest 4 5WORKDIR /HEW2020/client 6COPY . . 7RUN yarn install --ignore-engines --network-timeout 1000000 8CMD ["yarn", "start"] 9EXPOSE 3000
Docker
1// server 2 3FROM golang:1.12 4 5ENV GO111MODULE=on 6 7WORKDIR /go/src/HEW2020/server 8COPY . . 9RUN go get github.com/pilu/fresh 10CMD ["fresh"] 11EXPOSE 49200 49201
Docker
1// envoy 2 3FROM envoyproxy/envoy:v1.12.2 4WORKDIR /HEW2020/proxy 5COPY ./envoy.yaml . 6CMD /usr/local/bin/envoy -c /HEW2020/proxy/envoy.yaml 7EXPOSE 8080
Docker
1// docker-compose.yml 2 3version: "3" 4 5services: 6 proxy: 7 build: ./proxy 8 volumes: 9 - ./proxy:/HEW2020/proxy 10 ports: 11 - "8080:8080" 12 links: 13 - "server" 14 container_name: "hew2020-proxy" 15 16 server: 17 build: ./server 18 volumes: 19 - ./server:/go/src/HEW2020/server 20 ports: 21 - "49200:49200" 22 container_name: "hew2020-server" 23 24 client: 25 build: ./client 26 volumes: 27 - ./client:/HEW2020/client 28 ports: 29 - "3000:3000" 30 container_name: "hew2020-client" 31 32 db: 33 image: mysql:5.7 34 restart: always 35 volumes: 36 - ../mysql/data:/var/lib/mysql 37 - ../mysql/conf:/etc/mysql/conf.d 38 - ../mysql/initdb.d:/docker-entrypoint-initdb.d 39 environment: 40 MYSQL_ROOT_PASSWORD: secret 41 MYSQL_DATABASE: hew2020 42 MYSQL_USER: root 43 MYSQL_PASSWORD: secret 44 # TZ: 'Asia/Tokyo' 45 ports: 46 - "13306:3306" 47 container_name: hew2020-db
Envoy
1// envoy.yaml 2 3admin: 4 access_log_path: /tmp/admin_access.log 5 address: 6 socket_address: { address: 0.0.0.0, port_value: 9901 } 7 8static_resources: 9 listeners: 10 - name: listener_0 11 address: 12 # 全IPの8080PortでListen 13 socket_address: { address: 0.0.0.0, port_value: 8080 } 14 filter_chains: 15 - filters: 16 - name: envoy.http_connection_manager 17 config: 18 codec_type: auto 19 stat_prefix: ingress_http 20 route_config: 21 name: local_route 22 virtual_hosts: 23 - name: local_service 24 domains: ["*"] 25 routes: 26 - match: { prefix: "/" } 27 route: 28 cluster: web_app_service 29 max_grpc_timeout: 0s 30 cors: 31 allow_origin: 32 - "*" 33 allow_methods: GET, PUT, DELETE, POST, OPTIONS 34 allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout 35 max_age: "1728000" 36 expose_headers: custom-header-1,grpc-status,grpc-message 37 http_filters: 38 - name: envoy.grpc_web 39 - name: envoy.cors 40 - name: envoy.router 41 clusters: 42 - name: web_app_service 43 connect_timeout: 0.25s 44 type: logical_dns 45 http2_protocol_options: {} 46 upstream_connection_options: 47 tcp_keepalive: 48 keepalive_time: 300 49 lb_policy: round_robin 50 # win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below 51 hosts: 52 [ 53 { 54 socket_address: 55 { address: host.docker.internal, port_value: 49200 }, 56 }, 57 ]
TypeScript
1// Signup.tsx 2 3import { SexTypes } from "../../proto/enums_pb" 4import { SignUpRequest } from "../../proto/messages_pb" 5import { WebAppServiceClient } from "../../proto/web_app_service_pb_service" 6 7const Signup: React.FC = () => { 8 const classes = useStyles() 9 10 useEffect(() => { 11 const req = new SignUpRequest() 12 req.setName("MyName") 13 req.setSex(SexTypes.SEX_MALE) 14 req.setAge(22) 15 req.setUserId("abcdefg") 16 req.setUserPw("password") 17 18 const client = new WebAppServiceClient("http://localhost:8080", {}) 19 client.signUp(req, (err, res) => { 20 if (err || res === null) { 21 throw err 22 } 23 console.log(res.getMessage()) 24 }) 25 }) 26 return ( 27 <Root> 28 <div className={classes.toolbar} /> 29 <h1>Signup</h1> 30 <h1>Signup</h1> 31 <h1>Signup</h1> 32 </Root> 33 ) 34}
ProtocolBuffers
1// web_app_service.proto 2 3web_app_service_proto 4service WebAppService { 5 rpc SignUp (messages.SignUpRequest) returns (messages.AuthResponse) {} 6}
ProtocolBuffers
1// messages.proto 2 3message AuthResponse { 4 bool status = 1; 5 enums.StatusCodes status_code = 2; 6 string token = 3; 7} 8message SignUpRequest { 9 string name = 1; 10 enums.SexTypes sex = 2; 11 uint32 age = 3; 12 string user_id = 4; 13 string user_pw = 5; 14}
追記
公式サイト(該当ページ)をチェックしてみたところ下記の様な記述がありました。
Two quick definitions, used by Envoy: Upstream connections are the service Envoy is initiating the connection to. Downstream connections are the client that is initiating a request through Envoy.
Upstream Connection Closed What it is: When the upstream closes the connection before the response is finished sending, Envoy cannot send a complete response to the downstream. Result: This depends on whether the downstream has started receiving data. If it has not (i.e. the upstream disconnects quickly), the downstream connection is reset. If it has, the downstream receives an HTTP 503 and the body text “upstream connect error or disconnect/reset before headers”
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。