d-Rickyy-b / node-red-contrib-ffpass

Node-RED module that enables you to control your Ford car via the FordPass API.
MIT License
1 stars 0 forks source link

Status node causes node-red crash when vehicle is in deep sleep #8

Open uncarvedblock78 opened 1 year ago

uncarvedblock78 commented 1 year ago

a 404 error occurs somewhere in the ffpass-status node when the vehicle is in deep sleep. this results in node-red crashing entirely.

d-Rickyy-b commented 1 year ago

Hi there and thanks for creating an issue. Do you happen to have more information on this issue? Any logs?

This is taken from the NodeRed documentation:

If a node throws an uncaught error, Node-RED will stop the entire flow as the state of the system is no longer known.

To me it sounds like unintended behavior when NodeRed crashes entirely. Could you please note down your NodeRed version, your nodejs version and any further information that could help me locate the bug?

uncarvedblock78 commented 1 year ago

Thanks for looking into this, I'm running the nodered/nodered:latest docker image on a synology NAS, I'll verify the node-red version and try to grab a log if my truck goes into deep sleep later this evening.

uncarvedblock78 commented 1 year ago

Node red version is 3.0.2

Updating status!
Error: Request failed with status code 404
    at createError (/data/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/data/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/data/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (node:events:539:35)
    at IncomingMessage.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  config: {
    url: '/api/vehicles/v5/**************************/statusrefresh/',
    headers: {
      Accept: '*/*',
      'User-Agent': 'FordPass/5 CFNetwork/1327.0.4 Darwin/21.2.0',
      'Accept-Language': 'en-US,en;q=0.9',
      'Accept-Encoding': 'gzip, deflate, br',
      'Application-Id': '71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592',
      'auth-token': '*********************************'
    },
    baseURL: 'https://usapi.cv.ford.com',
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    method: 'get',
    data: undefined
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: false,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: 0,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'usapi.cv.ford.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'usapi.cv.ford.com',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 230588496,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: false,
      [Symbol(kSetKeepAliveInitialDelay)]: 0,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object],
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'GET /api/vehicles/v5/****************/statusrefresh/ HTTP/1.1\r\n' +
      'Accept: */*\r\n' +
      'User-Agent: FordPass/5 CFNetwork/1327.0.4 Darwin/21.2.0\r\n' +
      'Accept-Language: en-US,en;q=0.9\r\n' +
      'Accept-Encoding: gzip, deflate, br\r\n' +
      'Application-Id: 71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592\r\n' +
      'auth-token: ****************************************\r\n' +
      'Host: usapi.cv.ford.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'GET',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/api/vehicles/v5/***************/statusrefresh/',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 404,
      statusMessage: 'Resource Not Found',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://usapi.cv.ford.com/api/vehicles/v5/***************/statusrefresh/',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 8,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'usapi.cv.ford.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 0,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://usapi.cv.ford.com/api/vehicles/v5/*****************/statusrefresh/',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'user-agent': [Array],
      'accept-language': [Array],
      'accept-encoding': [Array],
      'application-id': [Array],
      'auth-token': [Array],
      host: [Array]
    }
  },
  response: {
    status: 404,
    statusText: 'Resource Not Found',
    headers: {
      'content-length': '54',
      'content-type': 'application/json',
      date: 'Fri, 28 Oct 2022 10:48:12 GMT',
      connection: 'close'
    },
    config: {
      url: '/api/vehicles/v5/*****************/statusrefresh/',
      headers: [Object],
      baseURL: 'https://usapi.cv.ford.com',
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      transitional: [Object],
      method: 'get',
      data: undefined
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: false,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'GET /api/vehicles/v5/**********************/statusrefresh/ HTTP/1.1\r\n' +
        'Accept: */*\r\n' +
        'User-Agent: FordPass/5 CFNetwork/1327.0.4 Darwin/21.2.0\r\n' +
        'Accept-Language: en-US,en;q=0.9\r\n' +
        'Accept-Encoding: gzip, deflate, br\r\n' +
        'Application-Id: 71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592\r\n' +
        'auth-token: **********************************************************************\r\n' +
        'Host: usapi.cv.ford.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'GET',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/api/vehicles/v5/**************************/statusrefresh/',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'usapi.cv.ford.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { statusCode: 404, message: 'Resource not found' }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}
28 Oct 06:48:13 - [red] Uncaught Exception:
28 Oct 06:48:13 - [error] TypeError: Cannot read properties of undefined (reading 'data')
    at /data/node_modules/ffpass/index.js:328:101
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
28 Oct 06:48:27 - [info] 
uncarvedblock78 commented 1 year ago

after the above error occurs, the container restarts

uncarvedblock78 commented 1 year ago

UPDATE: My vehicle's battery has been replaced so it is no longer entering deep sleep consistently.

EDIT: Nevermind, as far as I can tell this 404 error is occurring only when vehicle is in deep sleep.

Thanks for your work on this!

firnich commented 1 year ago

Unfortunately I'm facing the same problem. When my car is in deep sleep (which it does to save battery on lower temperatures) the save error occurs and crashes the node-red container. Please let me know if you need any logs or additional information.

d-Rickyy-b commented 1 year ago

Hi there @firnich, I haven't found the time to check the issue yet. I'll let you know if I need logs or other information for debugging.

d-Rickyy-b commented 1 year ago

Hmm I might have found the issue and tried to fix it (https://github.com/d4v3y0rk/ffpass-module/commit/0f7ed476f3945e05269ba22d128228d951e6eeb0). No promises though. I'll release another version of the node-red module with the new dependency of ffpass v1.1.1

firnich commented 1 year ago

Thank you for the fix (this is quick). Unfortunately I'm traveling for the next two days without any access to my environment, but I hope I can give it a try on Friday.

d-Rickyy-b commented 1 year ago

No worries. Maybe you or @uncarvedblock78 are able to test it during the next few days or so. At least from the provided error message above it looks like this was the error. I don't own a ford myself, hence it's pretty tricky for me to try and reproduce the issue. Let me know what you found.

d-Rickyy-b commented 1 year ago

Hi @firnich, @uncarvedblock78, did anyone of you manage to check if my fix did work? If yes, I'd close this issue. If no, please let me know.

uncarvedblock78 commented 1 year ago

I've since updated to the latest release and had the container crash again while the vehicle is in deep sleep. (my Maverick seems to be eating batteries at this point) I haven't had a chance to review the logs to determine if it may be the same error though.