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

Add timeout when making requests to Uplink #1950

Merged
merged 23 commits into from
Jul 19, 2022

Conversation

benweatherman
Copy link
Contributor

@benweatherman benweatherman commented Jul 1, 2022

This is a series of changes that will hopefully fix or shed light on why we've gotten several reports of "gateway stops polling Uplink".

  1. Set a timeout when making a request because it's good practice for good reason. To me, this is the most likely culprit of the actual issue.
  2. Consolidate fallbackPollIntervalMs and earliestFetchDate into pollIntervalMs in UplinkSupergraphManager. This makes the code easier to follow, and simplifies where and how we set UplinkSupergraphManager.pollIntervalMs.
  3. Don't use async-retry.onRetry asynchronously because that function is called synchronously, and was resulting in some odd behavior.
    • I didn't use pollIntervalMs as minTimeout, so that defaults to 1000ms
    • I hardcoded maxTimeout to 60_000 ms so we'll never reach the default Infinity (maxRetries would have to be set very high to reach Infinity, but this is a safer option)
    • We're relying on the default behavior of the underlying node-retry library to set time between retries.
  4. Add logging to help determine when important things happen like polling (or not) and updating the schema (or not).

It's an internal function, it's OK to make it newly required
- Use `onRetry` synchronously
- Set a `maxTimeout` since the current default is `Infinity`
- Remove `earliestFetchTime` because it wasn't doing what we thought and it's not super helpful in a datetime format when we already have a similar notion as an absolute delay in ms.
- Add logging
@netlify
Copy link

netlify bot commented Jul 1, 2022

Deploy Preview for apollo-federation-docs canceled.

Name Link
🔨 Latest commit 7ab4f8e
🔍 Latest deploy log https://app.netlify.com/sites/apollo-federation-docs/deploys/62d6fe257f271200090a0e32

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 1, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

It makes types show up better in my editor
I don't think we want to give this power to everyone
Our `FetcherRequestInit` type doesn't include `timeout` (though most implementations support that).

There's also `signal` that `node-fetch` supports and is in the `minipass-fetch` API (the library the underlies `make-fetch-happen`), but the types aren't updated correctly.

Rather than dealing with either of these things directly, I'm just adding locally for now. In general, we may not want to allow users to pass in a custom fetcher for Uplink anyway.
Trying to keep the number of random exports we have down, so exposing default uplink info via the `UplinkSupergraphManager` class makes most sense
- Consolidate `fallbackPollIntervalMs` and `minDelayMs` into `pollIntervalMs` in `UplinkSupergraphManager`
- Set `pollIntervalMs` in `updateSupergraphSdl`, since that's needed both during init and during polling
- Moved checking `pollIntervalMs` out of the main gateway code so that more Uplink logic can live in `UplinkSupergraphManager`
Add `AbortableFetcher` and its ilk to support a `Fetcher` that also has a `signal` field, which is used implement the timeout pattern in standard web `fetch`. This also adds a `requestTimeout` property to `UplinkSupergraphManager`, though I didn't expose it in the constructor because I'm not sure if that's a knob we want to expose yet.
@benweatherman benweatherman marked this pull request as ready for review July 12, 2022 16:09
@benweatherman benweatherman changed the title Improve Gateway logging and 3rd-party library usage Add timeout when making requests to Uplink Jul 12, 2022
@benweatherman benweatherman modified the milestone: 2.1.0 Jul 12, 2022
Copy link
Contributor

@pcmanus pcmanus left a comment

Choose a reason for hiding this comment

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

Had a quick look. I realise that I really don't know these parts of the code and would need more time to understand this better, but didn't saw anything wrong and the reasonings make sense to me.

We can technically still set property values, but TS will complain. We can abuse that functionality to make our tests behave like we want. This is better than special-casing the value so users don't accidentally get lower values in their test environments.
I think we'll get less test cross-talk this way
@benweatherman benweatherman merged commit 2a4cdd1 into main Jul 19, 2022
@benweatherman benweatherman deleted the weatherman/gateway-quality-of-life branch July 19, 2022 19:01
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