关于 nginx:epoll_wait() 报客户端过早关闭连接,所以在向上游发送请求的同时也关闭了上游连接

epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream

我有一个网页,它运行良好。但是对于只有一个路径 /user/reg 它给出了 502 错误代码,因为该路径需要更多的时间来处理,所以我已经向容器添加了活性和就绪性探测器,但仍然有同样的问题。我正在使用 Kubernetes 入口和 GCP 中部署的完整堆栈。

下面是我的入口配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
      kubernetes.io/ingress.global-static-ip-name:"nonprod"
      ingress.kubernetes.io/force-ssl-redirect:"true"
      kubernetes.io/ingress.allow-http:"false"
      ingress.kubernetes.io/upstream-max-fails:"999"
      ingress.kubernetes.io/upstream-fail-timeout:"999"
  name: nonprod
  namespace: nonprod
spec:
  tls:
  - hosts:
    - hostname.example.com
    secretName: nonprod-tls
  rules:
    - host: hostname.example.com
      http:
        paths:
        - path: /*
          backend:
            serviceName: nonprod-nodeport
            servicePort: 80

下面是我的部署 yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  image: gcr.io/image:v1
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 80
            scheme: HTTP
          initialDelaySeconds: 180
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        name: drupal
        ports:
        - containerPort: 80
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 80
            scheme: HTTP
          initialDelaySeconds: 180
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          limits:
            cpu:"1"
            memory: 2Gi
          requests:
            cpu:"1"
            memory: 2Gi

我检查了其他类似的问题,但没有帮助

当我检查日志时

1
2
3
4
5
6
2020/03/20 06:46:35 [info] 91#91: *60234 epoll_wait() reported that client prematurely closed connection, so upstream connection is closed too while sending request to upstream, clie
nt: 10.44.0.1, server: example.com, request:"POST /user/register HTTP/1.1", upstream:"fastcgi://unix:/var/run/php-fpm.sock:", host:"hostname.example.com", referre
r:"https://hostname.example.com/user/register"
10.44.0.1 - - [20/Mar/2020:06:46:35 +0000]"POST /user/register HTTP/1.1" 499 0"https://hostname.example.com/user/register""Mozilla/5.0 (Macintosh; Intel Mac OS X
10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36 Edg/80.0.361.66""27.59.32.87, 34.107.231.112"
10.44.0.1 - - [20/Mar/2020:06:46:35 +0000]"GET / HTTP/1.1" 200 17662"-""kube-probe/1.15+""-"


我可以通过增加 LoadBalancer 后端服务器超时来解决这个问题