程序加入处理text/xml数据程序后一直报A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET错误,但不影响使用
为了接受来自微信服务器的推送时间消息我在程序中加入了一段处理xml数据的程序。 const xml2js = require('xml2js').parseString; class xmlparserService extends Service {
async xmlpaser(){
let that = this;
return new Promise((resolve,reject)=>{
let data = '';
let json = {};
that.ctx.req.setEncoding('utf8');
that.ctx.req.on('data',function(chunk){
data += chunk;
});
that.ctx.req.on('end',function(){
xml2js(data,{},function(err,json){
//自己的操作
console.log("res is "+JSON.stringify(json));
resolve(json);
})
});
});
}
} module.exports =xmlparserService;
程序一切正常也能返回解析后的xml数据;但是只要微信频率稍微快一点发送消息过来过后一段时间就会报一下错误: 2018-08-07 23:42:32,508 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,509 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,511 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,512 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 我将上面程序进行trycatch也捕捉不到信息; 我实在是解决不了求大神解答,这个问题究竟是我本身程序问题,还是微信服务器端问题,还是其他什么问题
Translation of this issue:
The program has been reported to process the text/xml data program and has been reported to A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET error, but does not affect the use
In order to accept the push time message from the WeChat server, I added a program to process the xml data in the program. Const xml2js = require('xml2js').parseString; Class xmlparserService extends Service {
Async xmlpaser(){ Let that = this; Return new Promise((resolve,reject)=>{ Let data = ''; Let json = {}; that.ctx.req.setEncoding('utf8'); That.ctx.req.on('data',function(chunk){ Data += chunk; });
That.ctx.req.on('end',function(){ Xml2js(data,{},function(err,json){ //Own operation That.ctx.body = {}; Console.log("res is "+JSON.stringify(json)); Resolve(json); }) }); }); } } Module.exports =xmlparserService;
The program can return the parsed xml data if everything is normal; but as long as the WeChat frequency is slightly faster, the message will be reported after a while. 2018-08-07 23:42:32,508 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,509 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,511 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET 2018-08-07 23:42:32,512 ERROR 31036 A client (undefined:NaN) error [ECONNRESET] occurred: read ECONNRESET I will not catch the information by tryingcatch the above program. I really can't solve the big God answer.
我也遇到了同样的问题。 我换了个腾讯云的服务器域名就疯狂报错。
2018-08-07 23:20:52,679 ERROR 11864 A client (::ffff:58.87.81.180:16790) error [ECONNRESET] occurred: read ECONNRESET
本地开发或者用老的域名就没事。
不要直接操作 that.ctx.req 那是 Express 时代的写法。
不就是想要获取 ctx.request.body 么
我没有用ctx.req的语法,也有这个问题。 最诡异的是只要接入腾讯云的流量就会报这个错。
我知道这个ctx.req是express时代写法吗,可是跟这个报错没有关系吧。可是我已经更换使用co-wechat-body中间件在router.js下的微信事件推送接口上使用还是会出现同样的报错。 https://zhuanlan.zhihu.com/p/34147188?from_voters_page=true 这个链接有提到ECONNRESET出现的原因,但不知道是否是这个原因 @atian25 还有只是接入将服务部署到腾讯云上就会这样吗,我手头没有其他服务商的云服务器可以试,换到阿里云的不会报错吗,还有这么诡异的事情?? @bymaxchen
@xiaozhendong 原因找到了。 我们的腾讯云做了负载均衡,它会通过head方法轮询探测它方向代理的服务,然后它主动断开了。 你可以打印一下所有外部http请求,肯定能看到。 我们的解决办法就是直接将这个探测关闭。
我是个人开发,可是我没有做负载均衡啊,是腾讯云自带的负载均衡?依旧有这个问题啊 @bymaxchen
@xiaozhendong 你打印一下所有外部请求看看。
{ request:
{ method: 'POST',
url:
'/wechatAuth?signature=ca84bdf63dc35c3f306f6aaf08520b8a5c295bbd×tamp=1533800652&nonce=2137724051&openid=oiIRd1a5JnoNGFpboJm0TcF17xCw',
header:
{ 'user-agent': 'Mozilla/4.0',
accept: '/',
host: 'www.xiaozhendong1120.xyz',
pragma: 'no-cache',
'content-length': '507',
'content-type': 'text/xml' } },
response: { status: 404, message: 'Not Found', header: {} },
app:
{ env: 'local',
name: 'ElectronicDutySystem',
baseDir: '/home/ubuntu/ElectronicDutySystem',
subdomainOffset: 2,
config: '
是这个吗 @bymaxchen
可能是非 http 协议请求你的应用,这个协议都解不了你应用程序是打不出来的。
你可以使用这个把 socket 打出来 https://eggjs.org/api/Config.html#onClientError
应该是被本地的某个程序通过非 HTTP 协议进行扫描 Socket 了。
你可以在 config.default.js 里面加一个配置,输出 Client Error 时候的请求 Raw Packet 看看:
exports.onClientError = async (err, socket) => {
console.log(err);
console.log(err.rawPacket);
console.log(socket);
};
参考:https://eggjs.org/api/Config.html#onClientError
然后看看当复现的时候输出了什么。
{ request: { method: 'POST', url: '/wechatAuth?signature=ca84bdf63dc35c3f306f6aaf08520b8a5c295bbd×tamp=1533800652&nonce=2137724051&openid=oiIRd1a5JnoNGFpboJm0TcF17xCw', header: { 'user-agent': 'Mozilla/4.0', accept: '/', host: 'www.xiaozhendong1120.xyz', pragma: 'no-cache', 'content-length': '507', 'content-type': 'text/xml' } }, response: { status: 404, message: 'Not Found', header: {} }, app: { env: 'local', name: 'ElectronicDutySystem', baseDir: '/home/ubuntu/ElectronicDutySystem', subdomainOffset: 2, config: '', controller: '', httpclient: '', loggers: '', middlewares: '', router: '', serviceClasses: '' }, originalUrl: '/wechatAuth?signature=ca84bdf63dc35c3f306f6aaf08520b8a5c295bbd×tamp=1533800652&nonce=2137724051&openid=oiIRd1a5JnoNGFpboJm0TcF17xCw', req: '', res: '', socket: '' }
是这个吗 @bymaxchen
应该不是,如果是 Client Error 这个错误的话,是属于那种非 HTTP 协议或者是坏掉的 HTTP 协议请求才会报的错,并不能被解析成一个正常的请求参数对象。
{ Error: read ECONNRESET at TCP.onread (net.js:659:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
undefined
Socket { connecting: false, _hadError: false, _handle: null, _parent: null, _host: null, _readableState: ReadableState { objectMode: false, highWaterMark: 16384, buffer: BufferList { 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, emitClose: false, destroyed: true, defaultEncoding: 'utf8', awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: false, _events: { end: [ [Function: onReadableStreamEnd], [Function: bound socketOnEnd] ], drain: [ [Function: ondrain], [Function: bound socketOnDrain] ], timeout: [Function: socketOnTimeout], data: [Function: bound socketOnData], close: [Function: bound socketOnClose], resume: [Function: onSocketResume], pause: [Function: onSocketPause], error: [Function] }, _eventsCount: 8, _maxListeners: undefined, _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: true, decodeStrings: false, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: false, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: false, errorEmitted: true, emitClose: false, bufferedRequestCount: 0, corkedRequestsFree: { next: null, entry: null, finish: [Function: bound onCorkedFinish] } }, writable: false, allowHalfOpen: true, _sockname: null, _pendingData: null, _pendingEncoding: '', server: Server { _events: { request: [Function: handleRequest], connection: [Function: connectionListener], error: [Function], clientError: [Function] }, _eventsCount: 4, _maxListeners: undefined, _connections: 0, _handle: { close: [Function: close], listen: [Function: listen], ref: [Function: noop], unref: [Function: noop], getsockname: [Function: getsockname], onconnection: [Function: onconnection], owner: [Circular] }, _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, pendingResponseData: 0, maxHeadersCount: null, connectionKey: '4:null:80', [Symbol(IncomingMessage)]: { [Function: IncomingMessage] super: [Function] }, [Symbol(ServerResponse)]: { [Function: ServerResponse] super: [Function] }, [Symbol(asyncId)]: 309 }, _server: Server { _events: { request: [Function: handleRequest], connection: [Function: connectionListener], error: [Function], clientError: [Function] }, _eventsCount: 4, _maxListeners: undefined, _connections: 0, _handle: { close: [Function: close], listen: [Function: listen], ref: [Function: noop], unref: [Function: noop], getsockname: [Function: getsockname], onconnection: [Function: onconnection], owner: [Circular] }, _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, pendingResponseData: 0, maxHeadersCount: null, connectionKey: '4:null:80', [Symbol(IncomingMessage)]: { [Function: IncomingMessage] super: [Function] }, [Symbol(ServerResponse)]: { [Function: ServerResponse] super: [Function] }, [Symbol(asyncId)]: 309 }, parser: HTTPParser { '0': [Function: parserOnHeaders], '1': [Function: parserOnHeadersComplete], '2': [Function: parserOnBody], '3': [Function: parserOnMessageComplete], '4': [Function: bound onParserExecute], _headers: [], _url: '', _consumed: true, socket: [Circular], incoming: IncomingMessage { _readableState: [ReadableState], readable: false, _events: {}, _eventsCount: 0, _maxListeners: undefined, socket: [Circular], connection: [Circular], httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, headers: [Object], rawHeaders: [Array], trailers: {}, rawTrailers: [], aborted: false, upgrade: false, url: '/public/js/weChat/bindInfo.js', method: 'GET', statusCode: null, statusMessage: null, client: [Circular], _consuming: false, _dumped: true, _parsedUrl: [Url] }, outgoing: null, maxHeaderPairs: 2000, onIncoming: [Function: bound parserOnIncoming] }, on: [Function: socketOnWrap], _paused: false, _httpMessage: null, [Symbol(asyncId)]: 335, [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: Timeout { _called: false, _idleTimeout: -1, _idlePrev: null, _idleNext: null, _idleStart: 17924, _onTimeout: null, _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(unrefed)]: true, [Symbol(asyncId)]: 986, [Symbol(triggerId)]: 983 }, [Symbol(kBytesRead)]: 17052, [Symbol(kBytesWritten)]: 21085 }
@XadillaX 这是出现报错试打印的信息
我使用了 co-wechat-body,这个中间件只在处理微信服务器的接口上 @XadillaX @popomore ,是否是这个中间件引起的呢
感觉客户端主动断连的错不应该报出来,这里的逻辑我要改一下。
这个是由于微信服务器端主动断连导致的吗?是需要我等待更新下一个版本更新,这个报错才会消除吗 @XadillaX
这个是由于微信服务器端主动断连导致的吗?是需要我等待更新下一个版本更新,这个报错才会消除吗 @XadillaX
对的,我会修复这个问题,不过目前来说,对于你的业务逻辑没有任何影响,就是会多个报错比较烦。