chrisjshull / homebridge-nest

Nest plugin for HomeBridge
699 stars 112 forks source link

Cookies Method Frequently Fails After Restart #609

Closed NainRouge closed 1 year ago

NainRouge commented 1 year ago

Sometimes on restart of my Homebridge, the plugin will fail to connect with an EHOSTUNREACH error.

To Reproduce Steps to reproduce the behavior:

  1. Restart Homebridge.

Expected behavior It to not fail almost every other restart.

Include with your bug report this version info: Node v18.15.0 Homebridge 1.6.0

Config { "name": "Nest", "googleAuth": { "issueToken": "https://accounts.google.com/o/oauth2/iframerpc?action=issueToken&response_type=token%20id_token&login_hint=REMOVED.apps.googleusercontent.com&origin=https://home.nest.com&scope=openid profile email https://www.googleapis.com/auth/nest-account&ss_domain=https://home.nest.com&include_granted_scopes=true", "cookies": "REMOVED" }, "platform": "Nest" },

Error Error: connect EHOSTUNREACH 2607:f8b0:4009:808::200a:443 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) { errno: -113, code: 'EHOSTUNREACH', syscall: 'connect', address: '2607:f8b0:4009:808::200a', port: 443, config: { url: 'https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt', method: 'post', data: '{"embed_google_oauth_access_token":true,"expire_after":"3600s","google_oauth_access_token":"REMOVED","policy_id":"authproxy-oauth-policy"}', headers: { Accept: 'application/json, text/plain, /', 'Content-Type': 'application/json', Authorization: 'Bearer REMOVED', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36', Referer: 'https://home.nest.com', 'Content-Length': 341 }, transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 40000, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], transitional: { silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false } }, request: <ref *1> Writable { _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, afterWriteTickInfo: null, buffered: [], bufferedIndex: 0, allBuffers: true, allNoop: true, pendingcb: 0, constructed: true, prefinished: false, errorEmitted: false, emitClose: true, autoDestroy: true, errored: null, closed: false, closeEmitted: false,

},
_events: [Object: null prototype] {
  response: [Function: handleResponse],
  error: [Function: handleRequestError],
  socket: [Function: destroyOnTimeout]
},
_eventsCount: 3,
_maxListeners: undefined,
_options: {
  maxRedirects: 21,
  maxBodyLength: 10485760,
  protocol: 'https:',
  path: '/v1/issue_jwt',
  method: 'POST',
  headers: [Object],
  agent: undefined,
  agents: [Object],
  auth: undefined,
  hostname: 'nestauthproxyservice-pa.googleapis.com',
  port: null,
  nativeProtocols: [Object],
  pathname: '/v1/issue_jwt'
},
_ended: false,
_ending: true,
_redirectCount: 0,
_redirects: [],
_requestBodyLength: 341,
_requestBodyBuffers: [ [Object] ],
_onNativeResponse: [Function (anonymous)],
_currentRequest: 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: true,
  sendDate: false,
  _removedConnection: false,
  _removedContLen: false,
  _removedTE: false,
  strictContentLength: false,
  _contentLength: 341,
  _hasBody: true,
  _trailer: '',
  finished: false,
  _headerSent: true,
  _closed: false,
  socket: [TLSSocket],
  _header: 'POST /v1/issue_jwt HTTP/1.1\r\n' +
    'Accept: application/json, text/plain, */*\r\n' +
    'Content-Type: application/json\r\n' +
    'Authorization: Bearer REMOVED\r\n' +
    'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36\r\n' +
    'Referer: https://home.nest.com\r\n' +
    'Content-Length: 341\r\n' +
    'Host: nestauthproxyservice-pa.googleapis.com\r\n' +
    'Connection: close\r\n' +
    '\r\n',
  _keepAliveTimeout: 0,
  _onPendingData: [Function: nop],
  agent: [Agent],
  socketPath: undefined,
  method: 'POST',
  maxHeaderSize: undefined,
  insecureHTTPParser: undefined,
  joinDuplicateHeaders: undefined,
  path: '/v1/issue_jwt',
  _ended: false,
  res: null,
  aborted: false,
  timeoutCb: null,
  upgradeOrConnect: false,
  parser: null,
  maxHeadersCount: null,
  reusedSocket: false,
  host: 'nestauthproxyservice-pa.googleapis.com',
  protocol: 'https:',
  _redirectable: [Circular *1],
  [Symbol(kCapture)]: false,
  [Symbol(kBytesWritten)]: 0,
  [Symbol(kEndCalled)]: false,
  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: [Object: null prototype],
  [Symbol(errored)]: null,
  [Symbol(kUniqueHeaders)]: null
},
_currentUrl: 'https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt',
_timeout: null,
[Symbol(kCapture)]: false

}, response: undefined, isAxiosError: true, toJSON: [Function: toJSON], status: undefined }

adriancable commented 1 year ago

EHOSTUNREACH is a network level issue. Router problem, Wi-Fi problem, ISP issue, network stack setup issue on whatever device you’re running on. Not a problem with this plug-in, or with Homebridge.

NainRouge commented 1 year ago

Nothing is blocked in my network logs, though. Guess I’m buying Ecobee because this plug-in working consistently was the only thing keeping me with Nest.

NainRouge commented 1 year ago

A consistent failure every other homebridge restart, and it's "my network." What a joke.

NainRouge commented 1 year ago

The error message even says it's trying to connect to https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt which is a 404 page from Google.

"404. That’s an error.

The requested URL /v1/issue_jwt was not found on this server. That’s all we know."

But hey, it's my fault.

NainRouge commented 1 year ago

Line 195 in nest-connection.js is the start of the call to https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt, a literal dead link.

https://imgur.com/a/RFIFYsj

req = { method: 'POST', timeout: API_TIMEOUT_SECONDS * 1000, url: 'https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt', data: { embed_google_oauth_access_token: true, expire_after: '3600s', google_oauth_access_token: googleAccessToken, policy_id: 'authproxy-oauth-policy' }, headers: { 'Authorization': 'Bearer ' + googleAccessToken, 'User-Agent': NestEndpoints.USER_AGENT_STRING, // 'x-goog-api-key': this.config.googleAuth.apiKey, 'Referer': 'https://' + NestEndpoints.NEST_API_HOSTNAME } };

But please, tell me more about how my network is the cause of your failure.

adriancable commented 1 year ago

If you think you know better than me what the error produced by my plug-in means, why are you asking me for help? My statement that this is due to a network-side issue is correct. You are free not to believe that, but understand that you will then waste a lot of time troubleshooting in the wrong places. I suggest you think of things like: work out if this only happens just after a system restart. If so then maybe your IPv6 stack (or connection to the router) is not coming online soon enough. Consider adding a delay. Since it's resolving to an IPv6 address, consider disabling IPv6 on your machine and see if the issue goes away.

https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt is not a literal dead link. If you go to that page in your browser, it is making a GET request and that indeed returns 404 because that endpoint does not support GET requests.

As you will see from the line of code you posted, the plug-in is making a POST request which you can easily prove to yourself is not a dead link, e.g.

curl -X POST https://nestauthproxyservice-pa.googleapis.com/v1/issue_jwt

does not return 404.

NainRouge commented 1 year ago

Honestly, you come across as a jerk. I hope someday you realize that.

That said, I'll concede that I did a GET instead of a POST.

NainRouge commented 1 year ago

If a restart of the homebridge app, not the device, causes the IPv6 stack to mess up every other restart it’s a problem with either your plugin or homebridge.

meadeiator commented 1 year ago

For any other users who get the EHOSTUNREACH error, confirming that @adriancable is correct and when I received the error (first time after using plugin for years) it was a hiccup with an IPV6 address and my router. I was actually not aware of the issue until the plugin essentially "revealed" it. A simple restart of my router and container where Homebridge resides (and a new IPV6 connection with the router ) resolved the issue immediately. All is once again working perfectly. Adding comment as per the original recommendation on this thread, reconfirming the local network is resolving properly is a much more efficient use of time than focusing on the plugin. Appreciative of the plugin and your efforts to maintain it. Thank you.