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

Interface type explosion causes error on query #2935

Open
martin-svanberg-northvolt opened this issue Feb 8, 2024 · 3 comments
Open

Interface type explosion causes error on query #2935

martin-svanberg-northvolt opened this issue Feb 8, 2024 · 3 comments

Comments

@martin-svanberg-northvolt
Copy link

martin-svanberg-northvolt commented Feb 8, 2024

Describe the bug
Attempting to query an interface with many implementations results in an error.

To Reproduce

We have an interface (FactoryUnit) with more than 70 implementations. It's defined as follows:

interface FactoryUnit {
  id: ID!
  # ...
  unitState: FactoryUnitState
}

type FactoryUnitState {
  id: ID!
  # ...
}

We try to run the following query, which gives an error:

Query:

query {
	identity(id: "...") {
		id
		... on FactoryUnit { unitState { id } }
	}
}

Expected behavior
It should not return an error when querying.

Output

{
	"errors": [
		{
			"message": "value retrieval failed: router bridge error: the deno runtime raised an error: `request: couldn't receive response couldn't deserialize payload `6476623271848066925`: `deno: couldn't deserialize response : `Error(\"invalid neither null nor empty object: found Object {\\\"code\\\": String(\\\"QUERY_PLANNING_FAILED\\\"), \\\"exception\\\": Object {\\\"stacktrace\\\": Array [String(\\\"RangeError: Invalid array length\\\")]}}\", line: 0, column: 0)``.`",
			"extensions": {
				"code": "INTERNAL_SERVER_ERROR"
			}
		}
	]
}

Desktop (please complete the following information):
macOS Monterey, but issue also visible on the server running Alpine Linux 3.16

Additional context
We've traced this issue to the following function in Apollo Federation, which appears to be a function with exponential time and space complexity:

function flatCartesianProduct<V>(arr:V[][][]): V[][] {

It fails when trying to construct an array of length 2^70. Given the comment above flatCartesianProduct, it seems that this is a known issue.

@abernix abernix transferred this issue from apollographql/router Feb 12, 2024
@abernix
Copy link
Member

abernix commented Feb 12, 2024

Thanks for opening this. I'm moving this to the federation repository since anything that can be fixed will be in the federation repository, rather than in the Router itself.

@abernix
Copy link
Member

abernix commented Feb 12, 2024

As questions which could be worth understanding that I don't see provided:

  1. Are you using Federation 2.x to compose this supergraph? Or is this a Federation 0.x supergraph that you're running with Federation 2 runtimes?
  2. Are there any of your subgraphs which haven't been updated to Federation 2.x yet? (e.g., don't have @link directives in their SDL)?
  3. Can you provide a reproduction of this with a contrived set of subgraphs and interfaces & types?

@martin-svanberg-northvolt
Copy link
Author

  1. This is using Federation 2.3
  2. I've verified that all of them are on either 2.0 or 2.3
  3. Sure! Give me some time and I'll try to set up a minimal reproduction

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

No branches or pull requests

2 participants