我有一個用 Go 編寫的 gRPC 服務器 ( server),與 Python gRPC 客戶端 ( client) 進行通信。服務器偶爾會向基于 Go 的 http 服務器發送 http post 請求 ( sigsvc)。所有這些實例都作為通過 docker-compose 啟動的 docker 實例運行,共享相同的 docker 網絡。server這是創建和發送 http 請求的代碼部分:b := new(bytes.Buffer)txbytes, err := json.Marshal(tx)if err != nil { log.WithError(err).Error("failed to marshal transaction") return nil, err}b.Write(txbytes)resp, err := http.Post(sigsvc.signerURL, "application/json; charset=utf-8", b)if err != nil { log.WithError(err).Errorf("error signing transaction with signer %s", sigsvc.signerURL) return nil, err}defer resp.Body.Close()var signedTx types.Transactionerr = json.NewDecoder(resp.Body).Decode(&signedTx)if err != nil { log.WithError(err).Error("couldn't decode signed transaction") return nil, err}sigsvc.signerURL映射到類似http://signer:6666/signhttp 簽名者服務上處理請求的端點。 signer指docker-compose.yml規范中列出的服務名稱。調試日志已成功轉儲請求和請求正文。但是,顯然,將請求主體解碼為transaction類型的行永遠不會執行,因為沒有記錄錯誤或解碼的事務日志。在 上server,我不斷收到以下錯誤: error="Post http://signer:6666/sign: EOF"這是請求的登錄方式sigsvc:msg="\"POST /sign HTTP/1.1\\r\\nHost: signer:6666\\r\\nConnection: close\\r\\nAccept-Encoding: gzip\\r\\nConnection: close\\r\\nContent-Length: 10708\\r\\nUser-Agent: Go-http-client/1.1\\r\\n\\r\\n{\\\"nonce\\\":\\\"0x0\\\",\\\"gasPrice\\\":\\\"0x2540be400\\\",\\\"gas\\\":\\\"0x15c285\\\",\\\"to\\\":null,\\\"value\\\":\\\"0x0\\\",\\\"input\\\":\\\"0x6080604055",\\\"v\\\":\\\"0x0\\\",\\\"r\\\":\\\"0x0\\\",\\\"s\\\":\\\"0x0\\\",\\\"hash\\\":\\\"0xab55920fb3d490fc55ccd76a29dfb380f4f8a9e5d0bda4155a3b114fca26da0a\\\"}\"我嘗試在類似但簡化的 docker 設置上重現此錯誤,但失敗了。我試圖理解以下內容:如果由于 docker 上的特定設置而暴露的這段代碼有任何問題?或者,我是否需要查看一些 docker 設置細節來調試實例。
1 回答

犯罪嫌疑人X
TA貢獻2080條經驗 獲得超4個贊
問題在于 http 處理程序代碼to在此logrus調用中記錄字段的方式。
log.WithFields(log.Fields{
"txhash": tx.Hash().Hex(),
"nonce": tx.Nonce(),
"to": tx.To().Hex(),
"data": tx.Data(),
"gasLimit": tx.Gas(),
"gasPrice": tx.GasPrice(),
"value": tx.Value(),
}).Debug("Decoded transaction from request body")
在特定情況下,tx.To()調用返回nil,這意味著調用tx.To().Hex()將因嘗試對指針進行方法調用而導致錯誤nil。從表面上看,人們預計調用log.WithFields()會出錯或出現恐慌,但處理程序會默默地關閉與客戶端的連接以獲得 EOF 響應。
- 1 回答
- 0 關注
- 130 瀏覽
添加回答
舉報
0/150
提交
取消