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(gatsby): Fix OOM from telemetry storing too much #22752

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/gatsby/src/query/graphql-runner.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import crypto from "crypto"
import {
parse,
validate,
Expand Down Expand Up @@ -164,9 +165,20 @@ export default class GraphQLRunner {
if (typeof statsQuery !== `string`) {
statsQuery = statsQuery.body
}
this.stats.uniqueOperations.add(`${statsQuery}${JSON.stringify(context)}`)

this.stats.uniqueQueries.add(statsQuery)
this.stats.uniqueOperations.add(
crypto
.createHash(`sha1`)
.update(statsQuery)
.update(JSON.stringify(context))
Copy link
Contributor

@sidharthachatterjee sidharthachatterjee Apr 2, 2020

Choose a reason for hiding this comment

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

We might not need the JSON.stringify anymore since crypto takes an object

Copy link
Contributor

Choose a reason for hiding this comment

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

This would also break on circular references (for the sake of creating a hash).

Can we either apply Sid's suggestion or at least use v8.serialize() for this? (That does support circular references, and a larger payload, although I certainly hope that's never an issue in this step)

.digest(`hex`)
)

this.stats.uniqueQueries.add(
crypto
.createHash(`sha1`)
.update(statsQuery)
.digest(`hex`)
)
}

const document = this.parse(query)
Expand Down