Commit ea5f8d0
committed
fix(@angular/build): preserve binary values in the SQLite cache store
The SQLite cache store serialized values with `JSON.stringify` and read them back
with `JSON.parse`. Several cached values contain binary data: the JavaScript
transformer stores its worker output as a `Uint8Array` (`Cache<Uint8Array>`), and
`CachedLoadResultEntry.contents` is typed as `string | Uint8Array`. A JSON round
trip cannot represent typed arrays, so those values came back from disk as plain
objects (`{"0":105,"1":109,...}`) and were handed to esbuild as load result
contents, failing the build with `"contents" must be a string or a Uint8Array`.
The failure only appeared from the second build onwards, because the first build
serves the value from the in-memory cache layer and the value is only corrupted
once it is read back from disk.
Values are now persisted using the V8 structured clone serialization API
(`node:v8`), which supports typed arrays natively and matches the behavior of the
LMDB store. The `value` column is declared as `BLOB` accordingly. Entries written
by a previous version of the store contain JSON text, which fails to deserialize
and is already handled as a cache miss, so those entries are simply recreated.
The store is only reached when LMDB fails to load, which is why this went
unnoticed on most systems. A common trigger is a prebuilt `@lmdb/lmdb-linux-x64`
binary requiring a newer glibc than the host provides, for example on Ubuntu
20.04, Debian 11, or RHEL/CentOS 8. The fallback can also be selected explicitly
with `NG_BUILD_CACHE_STORE=sqlite`.
Closes #338411 parent e3d55b2 commit ea5f8d0
2 files changed
Lines changed: 72 additions & 6 deletions
Lines changed: 15 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
12 | 21 | | |
13 | 22 | | |
14 | 23 | | |
| |||
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | | - | |
| 47 | + | |
39 | 48 | | |
40 | 49 | | |
41 | 50 | | |
| |||
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
95 | | - | |
| 104 | + | |
96 | 105 | | |
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
100 | 109 | | |
101 | | - | |
| 110 | + | |
102 | 111 | | |
| 112 | + | |
| 113 | + | |
103 | 114 | | |
104 | 115 | | |
105 | 116 | | |
| |||
116 | 127 | | |
117 | 128 | | |
118 | 129 | | |
119 | | - | |
| 130 | + | |
120 | 131 | | |
121 | 132 | | |
122 | 133 | | |
| |||
Lines changed: 57 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
39 | 94 | | |
40 | 95 | | |
41 | 96 | | |
| |||
89 | 144 | | |
90 | 145 | | |
91 | 146 | | |
92 | | - | |
93 | | - | |
| 147 | + | |
| 148 | + | |
94 | 149 | | |
95 | 150 | | |
96 | 151 | | |
| |||
0 commit comments