Repository navigation
Commit 16bf22f
authored
Revert: [flutter_tools] Fix DTD "Stream already subscribed" error and wait for analysis over DTD in widget preview (flutter#193637)
Reverts: [[flutter_tools] Fix DTD "Stream already subscribed" error and
wait for analysis over DTD in widget
preview](flutter#192930)
Initiated by: @jtmcdole
Reason for reverting: ```
Original PR Author: @bkonyi
Reviewed By: @DanTup
The original PR description is provided below:
## Description
During widget preview startup or file updates:
1. Concurrent calls to retrieve previews or wait for analysis (e.g.,
initial command startup racing with file watcher events) could
concurrently invoke `_waitForLspService()`, causing duplicate
`streamListen` calls to the Dart Tooling Daemon. DTD throws JSON-RPC
error 103 (`Stream already subscribed`) when a client attempts to
subscribe to a stream it is already listening to.
2. `WidgetPreviewDtdServices` previously considered the `Lsp` service
ready as soon as *any* `Lsp` method was registered on DTD (or upon
receiving the first `ServiceRegistered` event for `Lsp`). Because the
analysis server registers its LSP methods sequentially before posting an
`initialized` event on the `Lsp` stream, calls to
`Lsp.dart/workspace/analysis/complete` or
`Lsp.dart/workspace/getFlutterWidgetPreviews` could race ahead of their
registration and fail with `-32601 (method not found)`.
3. When connecting to a pre-existing analysis server over DTD
(`--dtd-url`), `LspPreviewDetector.analysisServer` is `null`, causing
`analysisServer?.waitForAnalysis()` calls during startup and file
updates to be no-ops.
This change:
- Deduplicates in-flight calls to `_waitForLspService()` using a shared
future (`_waitForLspServiceFuture`) so concurrent callers await the same
LSP registration check instead of issuing duplicate DTD requests.
- Separates `lspServiceAvailable` (whether an analysis server has begun
registering `Lsp` services on DTD) from `_allLspServicesRegistered`
(whether all required widget preview LSP methods in
`kRequiredLspServices` are registered), and updates
`_waitForLspServiceHelper()` to listen for the `initialized` event on
the `Lsp` stream before checking `getRegisteredServices()`.
- Consolidates LSP DTD calls into `_callLspService()` and removes the
`kMethodNotFound` polling loop now that `_waitForLspService()` ensures
all required LSP methods are registered.
- Safely catches and ignores `RpcErrorCodes.kStreamAlreadySubscribed` on
`streamListen` calls in `WidgetPreviewDtdServices` (`safeStreamListen`).
- Adds `WidgetPreviewDtdServices.waitForAnalysis()` (invoking
`Lsp.dart/workspace/analysis/complete` over DTD), unifies
`LspPreviewDetector.waitForAnalysis()` so widget preview waits for
analysis completion on both tool-managed and pre-existing analysis
servers, and moves the startup `waitForAnalysis()` call inside the DTD
error-handling `try / catch` block in `WidgetPreviewStartCommand`.
- Adds hermetic regression tests covering concurrent/pre-subscribed DTD
streams, partial vs. full LSP service registration (`Lsp.initialized`),
and waiting for analysis over DTD.
Fixes flutter#192424
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md1 parent 4e5a092 commit 16bf22f
7 files changed
Lines changed: 98 additions & 521 deletions
File tree
- packages/flutter_tools
- lib/src
- commands
- widget_preview
- test
- commands.shard
- hermetic/widget_preview
- permeable/widget_preview
- integration.shard
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
397 | 408 | | |
398 | 409 | | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
| 36 | + | |
38 | 37 | | |
39 | 38 | | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | | - | |
42 | 42 | | |
43 | | - | |
44 | | - | |
| 43 | + | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
| |||
76 | 75 | | |
77 | 76 | | |
78 | 77 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | 78 | | |
102 | 79 | | |
103 | 80 | | |
| |||
161 | 138 | | |
162 | 139 | | |
163 | 140 | | |
164 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
165 | 144 | | |
166 | 145 | | |
167 | 146 | | |
| |||
179 | 158 | | |
180 | 159 | | |
181 | 160 | | |
182 | | - | |
| 161 | + | |
183 | 162 | | |
184 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
185 | 166 | | |
186 | 167 | | |
187 | 168 | | |
188 | 169 | | |
189 | 170 | | |
190 | 171 | | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | 172 | | |
210 | | - | |
211 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
212 | 191 | | |
213 | 192 | | |
214 | | - | |
| 193 | + | |
215 | 194 | | |
216 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
217 | 214 | | |
218 | 215 | | |
219 | | - | |
220 | | - | |
221 | 216 | | |
222 | | - | |
| 217 | + | |
223 | 218 | | |
224 | 219 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | 220 | | |
244 | | - | |
245 | | - | |
| 221 | + | |
246 | 222 | | |
247 | | - | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
248 | 226 | | |
249 | 227 | | |
250 | | - | |
| 228 | + | |
251 | 229 | | |
252 | 230 | | |
253 | | - | |
254 | | - | |
255 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
256 | 234 | | |
257 | 235 | | |
| 236 | + | |
258 | 237 | | |
259 | | - | |
260 | 238 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
266 | 245 | | |
267 | 246 | | |
268 | | - | |
| 247 | + | |
269 | 248 | | |
270 | 249 | | |
271 | 250 | | |
272 | 251 | | |
273 | 252 | | |
274 | | - | |
| 253 | + | |
275 | 254 | | |
276 | 255 | | |
277 | 256 | | |
| |||
308 | 287 | | |
309 | 288 | | |
310 | 289 | | |
311 | | - | |
| 290 | + | |
312 | 291 | | |
313 | 292 | | |
314 | 293 | | |
| |||
400 | 379 | | |
401 | 380 | | |
402 | 381 | | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
128 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
129 | 134 | | |
130 | 135 | | |
131 | 136 | | |
| |||
180 | 185 | | |
181 | 186 | | |
182 | 187 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 188 | | |
194 | 189 | | |
195 | 190 | | |
| |||
201 | 196 | | |
202 | 197 | | |
203 | 198 | | |
204 | | - | |
| 199 | + | |
205 | 200 | | |
206 | 201 | | |
207 | 202 | | |
| |||
0 commit comments