Unverified Commit a7ca0459 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Fix: Missing null check in LRU cleanup (#87124)

Unfortunately this field is not strongly typed because it's a cyclic
type and I wasn't able to soundly model it with TypeScript. Skill issue
I'm sure.

Don't have an exact repro yet but the previous code was obviously wrong.

The way this should have been structured regardless is to delete the
wrapper MapEntry object instead of the value it contains. The
non-nullness of the wrapper object _is_ properly typed, and avoids an
unnecessary indirection.

As a follow up, I'll look into how to model this type properly.
parent ea927b58
...@@ -396,7 +396,7 @@ function dropRef<V extends MapValue>(value: V): void { ...@@ -396,7 +396,7 @@ function dropRef<V extends MapValue>(value: V): void {
value.ref = null value.ref = null
} }
function deleteMapEntry<V extends MapValue>(entry: MapEntry<V>): void { export function deleteMapEntry<V extends MapValue>(entry: MapEntry<V>): void {
// Delete the entry from the cache. // Delete the entry from the cache.
const emptyEntry: EmptyMapEntry<V> = entry as any const emptyEntry: EmptyMapEntry<V> = entry as any
emptyEntry.value = null emptyEntry.value = null
......
import type { MapEntry } from './cache-map' import type { MapEntry } from './cache-map'
import { deleteFromCacheMap } from './cache-map' import { deleteMapEntry } from './cache-map'
// We use an LRU for memory management. We must update this whenever we add or // We use an LRU for memory management. We must update this whenever we add or
// remove a new cache entry, or when an entry changes size. // remove a new cache entry, or when an entry changes size.
...@@ -119,7 +119,7 @@ function cleanup() { ...@@ -119,7 +119,7 @@ function cleanup() {
if (tail !== null) { if (tail !== null) {
// Delete the entry from the map. In turn, this will remove it from // Delete the entry from the map. In turn, this will remove it from
// the LRU. // the LRU.
deleteFromCacheMap(tail.value) deleteMapEntry(tail)
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment