上游过早关闭的连接,同时从上游客户端读取响应标头:

时间:2019-10-27 17:16:15

标签: google-app-engine go nginx google-cloud-platform

我将感谢您的帮助。我已经在Google App Engine上部署了Go。服务器关闭了一段时间,这意味着我们无法接收到消息。触发器来自上游过早关闭的连接,同时从上游(客户端)读取响应标头:错误:

2019/10/27 08:25:26 [error] 23#23: *166 upstream prematurely closed connection while reading response header from upstream, client: 169.x.x.x, server: _, request: "POST /api/v2/money/topup HTTP/1.1", upstream: "http://127.0.0.1:8081/api/v2/money/topup", host: “x.x.x”
{
 insertId: "5db55476000502bed07e4583"  
 labels: {
  clone_id: "00c61b117c10abbe48ef11bb1f4ad5987e3ba1611745455daf2a1d6634c62289065e6f871e6c"   
 }
 logName: "projects/showcase/logs/%2Fvar%2Flog%2Fnginx%2Ferror.log"  
 receiveTimestamp: "2019-10-27T08:25:26.334404825Z"  
 resource: {
  labels: {…}   
  type: "gae_app"   
 }
 textPayload: "2019/10/27 08:25:26 [error] 23#23: *166 upstream prematurely closed connection while reading response header from upstream, client: 169.254.1.1, server: _, request: "POST /api/v2/money/topup HTTP/1.1", upstream: "http://127.0.0.1:8081/api/v2/money/topup", host: “x.x.x””  
 timestamp: "2019-10-27T08:25:26.328382Z"  
}

图像分解如下:error log

我的Nginx.conf配置设置:

events {
    worker_connections 768;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 650;
    keepalive_requests 10000;
    types_hash_max_size 2048;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Logs will appear on the Google Developer's Console when logged to this
    # directory.
    access_log /var/log/app_engine/app.log;
    error_log /var/log/app_engine/app.log;

    gzip on;
    gzip_disable "msie6";

    server {
        # Google App Engine expects the runtime to serve HTTP traffic from
        # port 8080.
        listen 8080;
        root /usr/share/nginx/www;
        index index.html index.htm;
    }
}

对于app.yaml是:

runtime: go111
instance_class: F2
automatic_scaling:
min_idle_instances: 5
max_idle_instances: automatic  # default value
min_pending_latency: 30ms  # default value
max_pending_latency: automatic
max_concurrent_requests: 50

正在调用的函数:

func (h Handler) UpdateTopUps(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {

var payload model.C2BCallBack
defer r.Body.Close()
err := json.NewDecoder(r.Body).Decode(&payload)
if err != nil {
    http.Error(w, "Bad Request", http.StatusBadRequest)
    return
}

str := spew.Sdump(payload)
log.Println(str)

id := uuid.NewV4()
if err != nil {
    fmt.Printf("Something went wrong: %s", err)
    return
}

if len(payload.MSISDN) > 0 {
    amount := strings.Split(payload.TransAmount, ".")
    balance := strings.Split(payload.OrgAccountBalance, ".")

    var phoneNumber string
    if strings.HasPrefix(payload.MSISDN, "07") {
        phoneNumber = "255" + payload.MSISDN[1:]
    } else {
        phoneNumber = payload.MSISDN
    }

    res := h.database.Create(&model.MpesaTransaction{MpesaTransactionId: id, TransID: payload.TransID, TransTime: payload.TransTime,
        TransAmount: amount[0], BusinessShortCode: payload.BusinessShortCode, OrgAccountBalance: balance[0],
        MSISDN: phoneNumber, FirstName: payload.FirstName, MiddleName: payload.MiddleName, LastName: payload.LastName})

    if err != nil {
        http.Error(w, "Internal Server Error", http.StatusInternalServerError)
        return
    }

    h.updateWalletBalance(res.Value)
}

}

有时可以工作,然后由于上述错误而失败。

0 个答案:

没有答案