Commit 5f45f76
authored
fix: prevent context loss by always setting thread and fiber locals (#497)
* Fix lost thread and fiber locals
Thread and fiber locals are being cleared on completion of every future.
If the promise ran on the same thread as the request, or the same thread
as the last promise, the locals are then not available. The execution
context hasn't changed in those circumstances so the code that sets the
locals at the start of a promise doesn't run.
1. Thread 1 runs
2. Sets context
3. Loads scope
4. Clears context
5. Thread 1 runs next scope
6. Context hasn’t changed so doesn’t set it again
7. Loads scope
8. Fails because the code relying on the context causes an exception
because the locals aren't available.
Instead always set the thread and fiber locals and only clear those that
we know are new. This should avoid the lost locals and also avoid
memory leaks between promises.
See: #496
* Fix account for Fiber.current.storage not being available
* Fix account for Fiber.current.storage not being available 2/1 parent e5b54b6 commit 5f45f76
1 file changed
+35
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
159 | 157 | | |
160 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
161 | 162 | | |
162 | | - | |
163 | | - | |
164 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
165 | 177 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 178 | + | |
| 179 | + | |
170 | 180 | | |
171 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
172 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
173 | 192 | | |
174 | 193 | | |
175 | 194 | | |
| |||
0 commit comments