-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix potential memory leak in
Concast
, add tests (#11358)
- Loading branch information
Showing
9 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@apollo/client": patch | ||
--- | ||
|
||
Fixes a potential memory leak in `Concast` that might have been triggered when `Concast` was used outside of Apollo Client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"dist/apollo-client.min.cjs": 38630, | ||
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32213 | ||
"dist/apollo-client.min.cjs": 38632, | ||
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 32215 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { MatcherFunction } from "expect"; | ||
|
||
// this is necessary because this file is picked up by `tsc` (it's not a test), | ||
// but our main `tsconfig.json` doesn't include `"ES2021.WeakRef"` on purpose | ||
declare class WeakRef<T extends WeakKey> { | ||
constructor(target: T); | ||
deref(): T | undefined; | ||
} | ||
|
||
export const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef<any>]> = | ||
async function (actual) { | ||
const hint = this.utils.matcherHint("toBeGarbageCollected"); | ||
|
||
if (!(actual instanceof WeakRef)) { | ||
throw new Error( | ||
hint + | ||
"\n\n" + | ||
`Expected value to be a WeakRef, but it was a ${typeof actual}.` | ||
); | ||
} | ||
|
||
let pass = false; | ||
let interval: NodeJS.Timeout | undefined; | ||
let timeout: NodeJS.Timeout | undefined; | ||
await Promise.race([ | ||
new Promise<void>((resolve) => { | ||
timeout = setTimeout(resolve, 1000); | ||
}), | ||
new Promise<void>((resolve) => { | ||
interval = setInterval(() => { | ||
global.gc!(); | ||
pass = actual.deref() === undefined; | ||
if (pass) { | ||
resolve(); | ||
} | ||
}, 1); | ||
}), | ||
]); | ||
|
||
clearInterval(interval); | ||
clearTimeout(timeout); | ||
|
||
return { | ||
pass, | ||
message: () => { | ||
if (pass) { | ||
return ( | ||
hint + | ||
"\n\n" + | ||
"Expected value to not be cache-collected, but it was." | ||
); | ||
} | ||
|
||
return ( | ||
hint + "\n\n Expected value to be cache-collected, but it was not." | ||
); | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters