HTTP套接字关闭连接已关闭

时间:2017-10-25 04:37:03

标签: javascript node.js sockets express

enter image description here

我在节点js中的表单提交上收到此错误。仅在帖子上传问题中,另一个商家上传成功完成,但问题仅在此部分。为什么我在上传的唯一帖子

中收到连接关闭问题
  var form = new FormData();
  form.append('data', JSON.stringify(req.body.request));
  form.append('file', fs.createReadStream('uploads/' + rename_f));

  form.submit({
    protocol: config.phpHostProt,
    hostname: config.phpHost,
    port: config.phpHostPort,
    path: '/api/addPost',
    headers: { 'Authorization': 'Bearer ' + authToken },
    agent: false
  }, function (err, res) {
    if (err) {
      logger.error(JSON.stringify(err));
      reject(err);
    } else if (res.statusCode !== 200) {
      logger.error(res);
      reject(res.statusMessage);
    } else {
      resolve();
    }
  });

res变量是打印像下面这样套接字连接是假的。如何设置连接始终是真的

    ServerResponse {
  domain: null,
  _events:
   { finish: [ [Function: resOnFinish], [Function: onevent] ],
     end: [Function: onevent] },
  _eventsCount: 2,
  _maxListeners: undefined,
  output: [],
  outputEncodings: [],
  outputCallbacks: [],
  outputSize: 0,
  writable: true,
  _last: false,
  upgrading: false,
  chunkedEncoding: false,
  shouldKeepAlive: true,
  useChunkedEncodingByDefault: true,
  sendDate: true,
  _removedHeader: {},
  _contentLength: null,
  _hasBody: true,
  _trailer: '',
  finished: false,
  _headerSent: false,
  socket:
   Socket {
     connecting: false,
     _hadError: false,
     _handle:
      TCP {
        bytesRead: 1382,
        _externalStream: {},
        fd: 23,
        reading: true,
        owner: [Circular],
        onread: [Function: onread],
        onconnection: null,
        writeQueueSize: 0 },
     _parent: null,
     _host: null,
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        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 },
     readable: true,
     domain: null,
     _events:
      { end: [Object],
        finish: [Function: onSocketFinish],
        _socketEnd: [Function: onSocketEnd],
        drain: [Object],
        timeout: [Function],
        error: [Object],
        close: [Object],
        data: [Function: socketOnData],
        resume: [Function: onSocketResume],
        pause: [Function: onSocketPause] },
     _eventsCount: 10,
     _maxListeners: undefined,
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        decodeStrings: false,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: true,
     destroyed: false,
     _bytesDispatched: 406,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server:
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 9,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        _pendingResponseData: 0,
        _connectionKey: '4:0.0.0.0:8443' },
     _server:
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 9,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        _pendingResponseData: 0,
        _connectionKey: '4:0.0.0.0:8443' },
     _idleTimeout: 120000,
     _idleNext:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 3175,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Object],
        _idlePrev: [Circular],
        _idleStart: 455361,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: null,
        _peername: [Object] },
     _idlePrev:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 4755,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Circular],
        _idlePrev: [Object],
        _idleStart: 455556,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: null,
        _peername: [Object] },
     _idleStart: 455450,
     parser:
      HTTPParser {
        '0': [Function: parserOnHeaders],
        '1': [Function: parserOnHeadersComplete],
        '2': [Function: parserOnBody],
        '3': [Function: parserOnMessageComplete],
        '4': [Function: onParserExecute],
        _headers: [],
        _url: '',
        _consumed: true,
        socket: [Circular],
        incoming: [Object],
        outgoing: null,
        maxHeaderPairs: 2000,
        onIncoming: [Function: parserOnIncoming] },
     on: [Function: socketOnWrap],
     _paused: false,
     read: [Function],
     _consuming: true,
     _httpMessage: [Circular],
     _peername: { address: '127.0.0.1', family: 'IPv4', port: 38132 } },
  connection:
   Socket {
     connecting: false,
     _hadError: false,
     _handle:
      TCP {
        bytesRead: 1382,
        _externalStream: {},
        fd: 23,
        reading: true,
        owner: [Circular],
        onread: [Function: onread],
        onconnection: null,
        writeQueueSize: 0 },
     _parent: null,
     _host: null,
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        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 },
     readable: true,
     domain: null,
     _events:
      { end: [Object],
        finish: [Function: onSocketFinish],
        _socketEnd: [Function: onSocketEnd],
        drain: [Object],
        timeout: [Function],
        error: [Object],
        close: [Object],
        data: [Function: socketOnData],
        resume: [Function: onSocketResume],
        pause: [Function: onSocketPause] },
     _eventsCount: 10,
     _maxListeners: undefined,
     _writableState:
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        decodeStrings: false,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
     allowHalfOpen: true,
     destroyed: false,
     _bytesDispatched: 406,
     _sockname: null,
     _pendingData: null,
     _pendingEncoding: '',
     server:
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 9,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        _pendingResponseData: 0,
        _connectionKey: '4:0.0.0.0:8443' },
     _server:
      Server {
        domain: null,
        _events: [Object],
        _eventsCount: 4,
        _maxListeners: undefined,
        _connections: 9,
        _handle: [Object],
        _usingSlaves: false,
        _slaves: [],
        _unref: false,
        allowHalfOpen: true,
        pauseOnConnect: false,
        httpAllowHalfOpen: false,
        timeout: 120000,
        _pendingResponseData: 0,
        _connectionKey: '4:0.0.0.0:8443' },
     _idleTimeout: 120000,
     _idleNext:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 3175,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Object],
        _idlePrev: [Circular],
        _idleStart: 455361,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: null,
        _peername: [Object] },
     _idlePrev:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 4755,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Circular],
        _idlePrev: [Object],
        _idleStart: 455556,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: null,
        _peername: [Object] },
     _idleStart: 455450,
     parser:
      HTTPParser {
        '0': [Function: parserOnHeaders],
        '1': [Function: parserOnHeadersComplete],
        '2': [Function: parserOnBody],
        '3': [Function: parserOnMessageComplete],
        '4': [Function: onParserExecute],
        _headers: [],
        _url: '',
        _consumed: true,
        socket: [Circular],
        incoming: [Object],
        outgoing: null,
        maxHeaderPairs: 2000,
        onIncoming: [Function: parserOnIncoming] },
     on: [Function: socketOnWrap],
     _paused: false,
     read: [Function],
     _consuming: true,
     _httpMessage: [Circular],
     _peername: { address: '127.0.0.1', family: 'IPv4', port: 38132 } },
  _header: null,
  _headers:
   { 'x-frame-options': 'SAMEORIGIN',
     'x-xss-protection': '1; mode=block',
     'x-content-type-options': 'nosniff',
     'x-download-options': 'noopen',
     'strict-transport-security': 'max-age=15778476; includeSubDomains',
     p3p: 'ABCDEF' },
  _headerNames:
   { 'x-frame-options': 'X-FRAME-OPTIONS',
     'x-xss-protection': 'X-XSS-Protection',
     'x-content-type-options': 'X-Content-Type-Options',
     'x-download-options': 'X-Download-Options',
     'strict-transport-security': 'Strict-Transport-Security',
     p3p: 'P3P' },
  _onPendingData: [Function: updateOutgoingData],
  req:
   IncomingMessage {
     _readableState:
      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: null,
        ended: true,
        endEmitted: false,
        reading: false,
        sync: true,
        needReadable: false,
        emittedReadable: true,
        readableListening: false,
        resumeScheduled: false,
        defaultEncoding: 'utf8',
        ranOut: false,
        awaitDrain: 0,
        readingMore: true,
        decoder: null,
        encoding: null },
     readable: true,
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     socket:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 406,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Object],
        _idlePrev: [Object],
        _idleStart: 455450,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: [Circular],
        _peername: [Object] },
     connection:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 406,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Object],
        _idlePrev: [Object],
        _idleStart: 455450,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: [Circular],
        _peername: [Object] },
     httpVersionMajor: 1,
     httpVersionMinor: 1,
     httpVersion: '1.1',
     complete: true,
     headers:
      { host: '...........',
        accept: 'application/json, text/plain, */*',
        'user-agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
        referer: '...........',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'en-US,en;q=0.8',
        cookie: 'sessionId=s%3AugXmFhK7IkiGhFJ0m-d-itmggdjB3BA-.CWMTzXfaoHQdHb9tEljRVFLZ8tn9N3fjV1c9HvpwPSQ',
        'if-none-match': 'W/"162fd1-D/VGV+JkfYYeCYIikVmSJw"',
        'x-forwarded-for': '103.251.16.223',
        'x-forwarded-host': '...........',
        'x-forwarded-server': '...........',
        connection: 'Keep-Alive' },
     rawHeaders:
      [ 'Host',
        '...........',
        'Accept',
        'application/json, text/plain, */*',
        'User-Agent',
        'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
        'Referer',
        '...........',
        'Accept-Encoding',
        'gzip, deflate, br',
        'Accept-Language',
        'en-US,en;q=0.8',
        'Cookie',
        'sessionId=s%3AugXmFhK7IkiGhFJ0m-d-itmggdjB3BA-.CWMTzXfaoHQdHb9tEljRVFLZ8tn9N3fjV1c9HvpwPSQ',
        'If-None-Match',
        'W/"162fd1-D/VGV+JkfYYeCYIikVmSJw"',
        'X-Forwarded-For',
        '103.251.16.223',
        'X-Forwarded-Host',
        '...........',
        'X-Forwarded-Server',
        '...........',
        'Connection',
        'Keep-Alive' ],
     trailers: {},
     rawTrailers: [],
     upgrade: false,
     url: '/api/referral-users',
     method: 'GET',
     statusCode: null,
     statusMessage: null,
     client:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [Object],
        _parent: null,
        _host: null,
        _readableState: [Object],
        readable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 10,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: true,
        allowHalfOpen: true,
        destroyed: false,
        _bytesDispatched: 406,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: [Object],
        _server: [Object],
        _idleTimeout: 120000,
        _idleNext: [Object],
        _idlePrev: [Object],
        _idleStart: 455450,
        parser: [Object],
        on: [Function: socketOnWrap],
        _paused: false,
        read: [Function],
        _consuming: true,
        _httpMessage: [Circular],
        _peername: [Object] },
     _consuming: false,
     _dumped: false,
     next: [Function: next],
     baseUrl: '',
     originalUrl: '/api/referral-users',
     _parsedUrl:
      Url {
        protocol: null,
        slashes: null,
        auth: null,
        host: null,
        port: null,
        hostname: null,
        hash: null,
        search: null,
        query: null,
        pathname: '/api/referral-users',
        path: '/api/referral-users',
        href: '/api/referral-users',
        _raw: '/api/referral-users' },
     params: {},
     query: {},
     res: [Circular],
     _startAt: [ 10164095, 67334257 ],
     _startTime: 2017-10-25T12:06:33.110Z,
     _remoteAddress: '127.0.0.1',
     body: {},
     originalMethod: 'GET',
     secret: undefined,
     cookies: { sessionId: 's:ugXmFhK7IkiGhFJ0m-d-itmggdjB3BA-.CWMTzXfaoHQdHb9tEljRVFLZ8tn9N3fjV1c9HvpwPSQ' },
     signedCookies: {},
     flash: [Function: _flash],
     _parsedOriginalUrl:
      Url {
        protocol: null,
        slashes: null,
        auth: null,
        host: null,
        port: null,
        hostname: null,
        hash: null,
        search: null,
        query: null,
        pathname: '/api/referral-users',
        path: '/api/referral-users',
        href: '/api/referral-users',
        _raw: '/api/referral-users' },
     sessionStore:
      E4Store {
        Session: Session,
        generate: [Function],
        _events: [Object],
        _eventsCount: 2 },
     sessionID: 'ugXmFhK7IkiGhFJ0m-d-itmggdjB3BA-',
     session: Session { cookie: [Object], passport: [Object] },
     _passport: { instance: [Object], session: [Object] },
     user:
      { _id: 1,
        merchant_id: 1,
        displayName: 'FlipNpik',
        provider: 'local',
        username: 'seedadmin',
        created: '0000-00-00',
        roles: [Object],
        profileImageURL: 'modules/users/client/img/profile/default.png',
        password: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmbGlwbnBpay5jb20iLCJvcmlnaW4iOiJwaHAiLCJtZXJjaGFudElEIjoiR2Vla2dlZWsxNyEifQ.jO5-_wDzanh1U_t1cALxgitLkfREyndZN-1Quqb6IIY',
        email: 'info@flipnpik.com',
        lastName: 'FlipNpik',
        firstName: '',
        resetPasswordToken: null,
        resetPasswordExpires: null },
     route:
      Route {
        path: '/api/referral-users',
        stack: [Object],
        methods: [Object] } },
  locals:
   { host: '...........',
     url: '...........' },
  flush: [Function: flush],
  write: [Function: write],
  end: [Function: end],
  on: [Function: on],
  writeHead: [Function: writeHead],
  _startAt: undefined,
  _startTime: undefined,
  __onFinished: { [Function: listener] queue: [ [Function: logRequest] ] } }

0 个答案:

没有答案