Commit c9e2140
authored
fix(runtime): read script caches into per-call buffers, publish them atomically (#468)
* fix(runtime): read script caches into per-call buffers, publish them atomically
tns::ReadBinary and the 3-arg tns::ReadText served every file up to 1 MiB
out of a process-global static buffer. LoadScriptCache handed that pointer
to V8 as CachedData(BufferNotOwned), which the deserializer reads for the
whole of CodeSerializer::Deserialize. Two Worker threads starting at once
both fread their code caches into the same buffer, so one deserialized bytes
the other was overwriting with a different file. Release V8 does not
checksum code caches, so the corrupted payload was followed until a bad
pointer dereferenced: EXC_BAD_ACCESS in Deserializer::ReadObject, seen in
production a few seconds after app launch, always with a second worker in
the same frame.
ReadBinary now returns a caller-owned heap buffer (LoadScriptCache uses
BufferOwned) and ReadText reads straight into its std::string; the shared
Buffer/BinBuffer statics are gone. WriteBinary writes through a mkstemp
file in the cache directory and renames it over the target, stamping the
source's mtime before publishing, so a reader never sees a half-written
cache and two first-time compilers of the same module no longer interleave
writes into one file. Both SaveScriptCache overloads share one helper.
WorkerConcurrentStartupTests starts 12 workers together against warm caches,
each loading six fixture modules in rotated orders. On a Release build of
TestRunner (Debug disables code caches) it fails on main with workers
reporting another module's value and one never reporting; it passes with
this change.
* fix(runtime): guard null code caches and arm the startup spec's timeout early
ScriptCompiler::CreateCodeCache returns nullptr for a script V8 declines to
serialize; both SaveScriptCache overloads dereferenced the result. They now
skip the write instead.
Jasmine 2.0.1 arms a spec's async timeout before invoking it, so raising
DEFAULT_TIMEOUT_INTERVAL inside WorkerConcurrentStartupTests' spec never
applied to that spec (the unfixed-runtime run timed out at exactly the 5 s
default). The interval is now raised in beforeEach and restored in afterEach.1 parent fd521ff commit c9e2140
17 files changed
Lines changed: 3905 additions & 98 deletions
File tree
- NativeScript/runtime
- TestRunner/app/tests
- concurrentStartup
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
247 | 246 | | |
248 | | - | |
249 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
250 | 255 | | |
251 | 256 | | |
252 | 257 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | | - | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 25 | | |
30 | 26 | | |
31 | 27 | | |
| |||
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
102 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 109 | + | |
113 | 110 | | |
114 | 111 | | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
121 | 117 | | |
122 | | - | |
123 | | - | |
124 | 118 | | |
125 | 119 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | 120 | | |
141 | 121 | | |
142 | 122 | | |
143 | | - | |
| 123 | + | |
144 | 124 | | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 125 | | |
151 | 126 | | |
152 | 127 | | |
153 | 128 | | |
154 | 129 | | |
155 | 130 | | |
156 | | - | |
| 131 | + | |
157 | 132 | | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 133 | + | |
164 | 134 | | |
165 | | - | |
| 135 | + | |
166 | 136 | | |
167 | 137 | | |
168 | | - | |
| 138 | + | |
| 139 | + | |
169 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
170 | 145 | | |
171 | | - | |
| 146 | + | |
| 147 | + | |
172 | 148 | | |
173 | 149 | | |
174 | | - | |
175 | | - | |
176 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
177 | 161 | | |
178 | 162 | | |
179 | 163 | | |
180 | | - | |
181 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
182 | 197 | | |
183 | | - | |
| 198 | + | |
184 | 199 | | |
185 | 200 | | |
186 | 201 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
1894 | 1893 | | |
1895 | 1894 | | |
1896 | 1895 | | |
1897 | | - | |
1898 | | - | |
| 1896 | + | |
1899 | 1897 | | |
1900 | 1898 | | |
1901 | 1899 | | |
1902 | 1900 | | |
1903 | | - | |
1904 | | - | |
1905 | | - | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
1906 | 1914 | | |
1907 | 1915 | | |
1908 | 1916 | | |
1909 | 1917 | | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
1910 | 1923 | | |
1911 | 1924 | | |
1912 | 1925 | | |
1913 | 1926 | | |
1914 | | - | |
1915 | | - | |
1916 | | - | |
1917 | | - | |
1918 | | - | |
1919 | | - | |
1920 | | - | |
1921 | | - | |
1922 | | - | |
| 1927 | + | |
1923 | 1928 | | |
1924 | | - | |
1925 | | - | |
1926 | | - | |
1927 | | - | |
1928 | | - | |
1929 | | - | |
1930 | | - | |
1931 | | - | |
1932 | | - | |
1933 | | - | |
1934 | | - | |
1935 | 1929 | | |
1936 | 1930 | | |
1937 | 1931 | | |
| |||
1944 | 1938 | | |
1945 | 1939 | | |
1946 | 1940 | | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
1947 | 1944 | | |
1948 | | - | |
1949 | 1945 | | |
1950 | 1946 | | |
1951 | 1947 | | |
1952 | | - | |
| 1948 | + | |
1953 | 1949 | | |
1954 | | - | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
1965 | 1950 | | |
1966 | 1951 | | |
1967 | 1952 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 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 | + | |
0 commit comments