apollographql / apollographql/federation

Does not fail on startup when one service is not available even when using `serviceHealthCheck`

Open
#303 4 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

I think this bug was already reported in the previous repo: https://github.com/apollographql/apollo-server/issues/3243
and is also loosely related to this other issue: https://github.com/apollographql/federation/issues/235.

According to the [documentation](https://www.apollographql.com/docs/federation/api/apollo-gateway/#servicehealthcheck) when using the `serviceHealthCheck` option it should fail on startup if a service doesn't return a successful healthcheck.
But it does not... an error about service definitions is logged and the gateway stays in a broken state with no valid schema.

# How to reproduce?
Simply by creating a gateway server with a service that simply does not exist in the list.
Note that activating `serviceHealthCheck` does not make any difference due to the problem highlighted bellow.

```javascript
const gateway = new ApolloGateway({
serviceList: [{name: "potato", url: "http://potato"}],
serviceHealthCheck: true,
});

const server = new ApolloServer({
gateway,
subscriptions: false,
});

server.applyMiddleware({ app, path: '/graphql' });
```

# First issue: shouldn't health checks be run before anything?
I think there is a problem here:
https://github.com/apollographql/federation/blob/a99f9350ffd031056a820f7c6d287e129bc9fd93/gateway-js/src/index.ts#L382
Shouldn't the health check be done first in `updateComposition()` method? Because they are done after the call to `updateServiceDefinitions()` which obviously fails if a service is down... but shouldn't it be the job of the health check to detect that before?
Indeed the error from:
https://github.com/apollographql/federation/blob/a99f9350ffd031056a820f7c6d287e129bc9fd93/gateway-js/src/index.ts#L399-L403
is never shown since we don't even reach that point (by the way the error message should probably be different on startup).

# Second issue: the error should not be caught
If I am not mistaken, the whole thing is then wrapped in a try/catch which silences the error being thrown.
https://github.com/apollographql/federation/blob/a99f9350ffd031056a820f7c6d287e129bc9fd93/gateway-js/src/index.ts#L536-L540
Indeed we get the error in the logs but no error is actually thrown after so the gateway is still running...

Contributor guide

Open the contributing guide

Research direction

Read gateway-js/src/index.ts around updateComposition(), updateServiceDefinitions(), and the try/catch near lines 536-540. Reproduce with the serviceList containing the unavailable potato service and serviceHealthCheck enabled; done means startup fails and the health-check error is surfaced instead of leaving the gateway running without a valid schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.