Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use @vercel/fetch to better guard against network glitches #216

Closed
wants to merge 2 commits into from

Conversation

ivarconr
Copy link
Member

No description provided.

@ivarconr ivarconr requested review from chriswk and SimenB February 19, 2021 10:56
@ivarconr
Copy link
Member Author

The disabled network test is not failing. A bit unsure on how to actually verify that the client still produces an error. (@vercel/fetch will do magic retries under the hood)

@SimenB
Copy link
Collaborator

SimenB commented Feb 19, 2021

At work we've set retry: { retries: 3 } and for the tests verifying behavior we make the call 4 times and expect the fourth to error out

Copy link
Member Author

@ivarconr ivarconr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running it locally with a lot of traffic I got this error:

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received null
    at validateString (internal/validators.js:120:11)
    at Url.parse (url.js:159:3)
    at urlParse (url.js:154:13)
    at fetchCachedDns (/home/ivarconr/code/unleash-client-node/node_modules/@vercel/fetch-cached-dns/index.js:62:30)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async /home/ivarconr/code/unleash-client-node/node_modules/@vercel/fetch-retry/index.js:52:23
    at async fetchRetry (/home/ivarconr/code/unleash-client-node/node_modules/@vercel/fetch-retry/index.js:48:14)
    at async vercelFetch (/home/ivarconr/code/unleash-client-node/node_modules/@vercel/fetch/index.js:74:11) {
  code: 'ERR_INVALID_ARG_TYPE',
  url: 'https://unleash.herokuapp.com/api/client/features',
  opts: {
    method: 'GET',
    timeout: 10000,
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    agent: HttpsAgent {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object],
      requests: {},
      sockets: {},
      freeSockets: [Object],
      keepAliveMsecs: 30000,
      keepAlive: true,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      freeSocketKeepAliveTimeout: 15000,
      timeout: 10000,
      socketActiveTTL: null,
      createSocketCount: 2,
      createSocketCountLastCheck: 0,
      createSocketErrorCount: 0,
      createSocketErrorCountLastCheck: 0,
      closeSocketCount: 0,
      closeSocketCountLastCheck: 0,
      errorSocketCount: 0,
      errorSocketCountLastCheck: 0,
      requestCount: 58,
      requestCountLastCheck: 0,
      timeoutSocketCount: 0,
      timeoutSocketCountLastCheck: 0,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    redirect: 'manual',
    onRedirect: [Function]
  }

const agent = getAgent(new URL('https://unleash.hosted.com'));
t.true(agent instanceof https.Agent);
});
import { buildHeaders } from '../lib/request';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit unsure on how to test that we get an agent with proper agent settings.

@@ -12,4 +14,4 @@ console.log('Fetching toggles from: http://unleash.herokuapp.com');

setInterval(() => {
console.log(`featureX enabled: ${isEnabled('featureX')}`);
}, 1000);
}, 100);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah, revert this, only me testing.

@@ -69,7 +65,6 @@ export const post = ({ url, appName, timeout, instanceId, headers, json }: PostR
fetch(url, {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably also configure our own retry options.

@ivarconr
Copy link
Member Author

It seems like fetch-retry passes custom retry options to fetch. This ends up destroying for nock, as it does not intercept the http calls when the method signature is incorrect.

I have opened an issue for this:
vercel/fetch-retry#40

@ivarconr
Copy link
Member Author

I have been testing this module and found quite a few bugs.

  1. 304 is not redirect. the included @vercel/fetch-cached-dns expects a "location" header set on the repsonse, and thus fails. bug: 304 is not redirect and do not include a "Location" header vercel/fetch-cached-dns#28
  2. @vercel/fetch-retry adds internal (not compliant fetch) options to the fetch call if you override fetch per call. bug: opts.retry should not be passed to fetch vercel/fetch-retry#40

Conclusion: We can not use this wrapper to guard against network errors, as it will introduce new once. Especially 1) is a problem for us.

@ivarconr ivarconr closed this Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants