消息:读取ECONNRESET,堆栈:错误:从Docker容器内的Go客户端调用HapiJs服务器时读取ECONNRESET

  • 节点版本 :6.11.1
  • 平台 :docker集装箱内的Ubuntu 14.04。
  • 子系统 :http

在运行hapijs服务器的Node项目中调用端点时遇到一个非常特殊的问题。 当端点被直接击中时,没有任何问题。

但是当我们从gohaqd实例中find它时,我们得到:

170809/044343.745, [log,connection,client,error] message: write EPIPE, stack: Error: write EPIPE at exports._errnoException (util.js:1018:11) at WriteWrap.afterWrite (net.js:800:14)

更经常

170809/040643.248, [log,connection,client,error] message: read ECONNRESET, stack: Error: read ECONNRESET at exports._errnoException (util.js:1018:11) at TCP.onread (net.js:568:26)

我知道错误代码意味着某个地方,应用程序正试图写入一个封闭的连接。 但是对于我的生活,我无法弄清楚在哪里。 日志本身是来自hapijs,如果我没有错, 这条线 ,但无法弄清楚为什么节点试图写封闭的连接,无论如何。

记住,这没有任何副作用。 该应用程序运行良好:|

我们打开了NODE_DEBUG=http, net ,得到如下结果。 阅读这些内容时,唯一突出的就是在第二次write ret = true行出现两次,如果这意味着什么的话。 有人能帮我理解这是什么意思吗?

第一个是直接敲击端点的时候:

 NET 422: onconnection NET 422: _read NET 422: Socket._read readStart HTTP 422: SERVER new http connection HTTP 422: SERVER socketOnParserExecute 333 NET 422: onread 775 NET 422: got data NET 422: _read HTTP 422: call onSocket 0 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 1 HTTP 422: outgoing message end. HTTP 422: call onSocket 1 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 2 HTTP 422: outgoing message end. HTTP 422: call onSocket 2 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 3 HTTP 422: outgoing message end. NET 422: _read NET 422: _read wait for connection NET 422: _read NET 422: _read wait for connection NET 422: _read NET 422: _read wait for connection NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: onread 438 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close NET 422: onread 438 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: onread 486 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close HTTP 422: write ret = true HTTP 422: outgoing message end. NET 422: onread -4095 NET 422: EOF NET 422: onSocketEnd ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: false, reading: false, sync: false, needReadable: false, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: onSocketFinish NET 422: oSF: ended, destroy ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: true, reading: false, sync: false, needReadable: false, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: has server NET 422: SERVER _emitCloseIfDrained NET 422: SERVER handle? true connections? 15 NET 422: emit close HTTP 422: server socket close 

下一个是从gohaqd,这是一个去客户点击terminal。

 NET 422: onread 405 NET 422: got data NET 422: _read NET 422: onconnection NET 422: _read NET 422: Socket._read readStart HTTP 422: SERVER new http connection HTTP 422: SERVER socketOnParserExecute 325 NET 422: onread 775 NET 422: got data NET 422: _read HTTP 422: call onSocket 0 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 1 HTTP 422: outgoing message end. HTTP 422: call onSocket 1 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 2 HTTP 422: outgoing message end. HTTP 422: call onSocket 2 0 HTTP 422: createConnection api.mixpanel.com:80: { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:' } NET 422: createConnection [ { servername: 'api.mixpanel.com', path: null, headers: {}, port: 80, host: 'api.mixpanel.com', _agentKey: 'api.mixpanel.com:80:', encoding: null }, [Function: oncreate] ] NET 422: pipe false null NET 422: connect: find host api.mixpanel.com NET 422: connect: dns options { family: undefined, hints: 32 } HTTP 422: sockets api.mixpanel.com:80: 3 HTTP 422: outgoing message end. NET 422: _read NET 422: _read wait for connection NET 422: _read NET 422: _read wait for connection NET 422: _read NET 422: _read wait for connection NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: afterConnect NET 422: _read NET 422: Socket._read readStart NET 422: onread 438 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close NET 422: onread 438 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: onread 486 NET 422: got data HTTP 422: AGENT incoming response! HTTP 422: AGENT isHeadResponse false NET 422: _read HTTP 422: AGENT socket.destroySoon() NET 422: onSocketFinish NET 422: oSF: not ended, call shutdown() NET 422: destroy undefined NET 422: destroy NET 422: close NET 422: close handle NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close NET 422: afterShutdown destroyed=true ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: false, endEmitted: false, reading: true, sync: false, needReadable: true, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: emit close HTTP 422: CLIENT socket onClose HTTP 422: removeSocket api.mixpanel.com:80: writable: false HTTP 422: HTTP socket close HTTP 422: write ret = true NET 422: afterWrite 0 NET 422: afterWrite call cb HTTP 422: write ret = true HTTP 422: outgoing message end. NET 422: onread -4095 NET 422: EOF NET 422: onSocketEnd ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { head: null, tail: null, length: 0 }, length: 0, pipes: null, pipesCount: 0, flowing: true, ended: true, endEmitted: false, reading: false, sync: false, needReadable: false, emittedReadable: false, readableListening: false, resumeScheduled: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null } NET 422: afterWrite 0 NET 422: afterWrite call cb NET 422: afterWrite -32 NET 422: write failure { Error: write EPIPE at exports._errnoException (util.js:1018:11) at WriteWrap.afterWrite (net.js:800:14) code: 'EPIPE', errno: 'EPIPE', syscall: 'write' } NET 422: destroy NET 422: close NET 422: close handle 170809/101228.947, [log,connection,client,error] message: write EPIPE, stack: Error: write EPIPE at exports._errnoException (util.js:1018:11) at WriteWrap.afterWrite (net.js:800:14) NET 422: has server NET 422: SERVER _emitCloseIfDrained NET 422: SERVER handle? true connections? 15 NET 422: emit close HTTP 422: server socket close 

去调用这个代码:

 // Sends a POST request to consumption endpoint with the SQS message as body func sendMessageToURL(msg string) bool { var resp *http.Response var err error endpoint := url if endpoint == "" { m := make(map[string]string) err := json.Unmarshal([]byte(msg), &m) if err != nil { log.Printf("Unable to parse JSON message to get the URL: %s", msg) return false } endpoint = m["url"] if endpoint == "" { log.Printf("No 'url' field found in JSON message: %s", msg) return false } } for { resp, err = httpClient.Post(endpoint, "application/json", bytes.NewBuffer([]byte(msg))) if err == nil { break } log.Printf("Error hitting endpoint, retrying after 1 second... Error: %s", err.Error()) time.Sleep(time.Second) } defer resp.Body.Close() // return true only if response is 200 OK if resp.StatusCode != 200 { bodyBytes, _ := ioutil.ReadAll(resp.Body) log.Printf("Error: Non OK response: %s Status Code: '%s' for sent message: '%s'", string(bodyBytes), resp.Status, msg) return false } return true }