I was working with no errors in Dart Analyzer for months. Today I updated Dart Code and Flutter to the latest version, now Dart Analyzer crashes in a matter of minutes with Cannot call write after a stream was destroyed. Lsp is off.
Log
[21:53:34] [VmService] [Info] [10] <== {"jsonrpc":"2.0","method":"streamNotify","params":{"streamId":"Extension","event":{"type":"Event","kind":"Extension","extensionKind":"Flutter.Frame","isolate":{"type":"@Isolate","id":"isolates\/239248081289867","name":"main","number":"239248081289867"},"timestamp":1596675212826,"extensionData":{"number":1283,"startTime":114055166406,"elapsed":8775,"build":2057,"raster":5387}}}}
...repeated 155 times
[21:54:48] [VmService] [Info] [10] Termination requested!
[21:54:48] [FlutterRun] [Info] [10] ==> [{"id":"5","method":"app.stop","params":{"appId":"a06e3c1c-3de6-4a5e-9901-0999050b8859"}}]
[21:54:48] [VmService] [Info] [10] VM service connection closed: 1006 ()
[21:54:48] [FlutterRun] [Info] [10] <== [{"id":"5","result":true}]
[21:54:48] [FlutterRun] [Info] [10] <== Application finished.
[21:54:48] [FlutterRun] [Info] [10] <== [{"event":"app.stop","params":{"appId":"a06e3c1c-3de6-4a5e-9901-0999050b8859"}}]
[21:54:48] [FlutterRun] [Info] [10] Process terminated! null, SIGTERM
[21:54:48] [VmService] [Info] [10] Process exited (sigterm)
[21:54:48] [VmService] [Info] [10] TERM: Requested to terminate with SIGINT...
[21:54:48] [VmService] [Info] [10] TERM: Did not need to terminate processes
[21:54:48] [VmService] [Info] [10] TERM: Removing all stored data...
[21:54:48] [VmService] [Info] [10] TERM: Waiting for process to finish...
[21:54:48] [VmService] [Info] [10] TERM: Disconnecting...
[21:54:49] [VmService] [Info] [10] Disconnect requested!
[21:54:49] [VmService] [Info] [10] TERM: Requested to terminate with SIGINT...
[21:54:49] [VmService] [Info] [10] TERM: Did not need to terminate processes
[21:54:49] [VmService] [Info] [10] TERM: Removing all stored data...
[21:54:49] [VmService] [Info] [10] TERM: Waiting for process to finish...
[21:54:49] [VmService] [Info] [10] TERM: Disconnecting...
[21:54:49] [General] [Info] Debugger:SessionDuration timing: 869329ms (Flutter)
[21:59:00] [Analyzer] [Info] ==> {"id":"79","method":"analysis.setSubscriptions","params":{"subscriptions":{"CLOSING_LABELS":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"],"FOLDING":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"],"OCCURRENCES":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"],"OUTLINE":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"]}},"clientRequestTime":1596675540740}
[21:59:00] [Analyzer] [Info] ==> {"id":"80","method":"analysis.updateContent","params":{"files":{"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart":{"content":"import 'dart:convert';\r\nimport 'dart:io';\r\n\r\nimport 'package:flutter/foundation.dart';\r\nimport 'package:flutter/material.dart';\r\nimport 'package:flutter/services.dart';\r\nimport 'package:flutter_alert/flutter_alert.dart';\r\nimport 'package:material_design_icons_flutter/material_design_icons_flutter.dart';\r\nimport 'package:moo…
[21:59:00] [Analyzer] [Info] ==> {"id":"81","method":"edit.getFixes","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","offset":0},"clientRequestTime":1596675540745}
[21:59:00] [Analyzer] [Info] ==> {"id":"82","method":"edit.getAssists","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":0,"offset":0},"clientRequestTime":1596675540747}
[21:59:00] [Analyzer] [Info] ==> {"id":"83","method":"edit.getAvailableRefactorings","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":0,"offset":0},"clientRequestTime":1596675540749}
[21:59:00] [Analyzer] [Info] ==> {"id":"84","method":"analysis.setPriorityFiles","params":{"files":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"]},"clientRequestTime":1596675540752}
[21:59:00] [Analyzer] [Info] ==> {"id":"85","method":"analysis.updateContent","params":{"files":{"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart":{"edits":[{"offset":0,"length":0,"replacement":"","id":""}],"type":"change"}}},"clientRequestTime":1596675540772}
[21:59:00] [Analyzer] [Info] ==> {"id":"86","method":"analysis.updateContent","params":{"files":{"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart":{"edits":[{"offset":0,"length":0,"replacement":"","id":""}],"type":"change"}}},"clientRequestTime":1596675540774}
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [Analyzer] [Info] ==> {"id":"87","method":"flutter.setSubscriptions","params":{"subscriptions":{"OUTLINE":["C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart"]}},"clientRequestTime":1596675540776}
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [Analyzer] [Info] ==> {"id":"88","method":"edit.getFixes","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","offset":18287},"clientRequestTime":1596675540974}
[21:59:00] [Analyzer] [Info] ==> {"id":"89","method":"edit.getAssists","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":14,"offset":18273},"clientRequestTime":1596675540976}
[21:59:00] [Analyzer] [Info] ==> {"id":"90","method":"edit.getAvailableRefactorings","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":14,"offset":18273},"clientRequestTime":1596675540978}
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:00] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:08] [Analyzer] [Info] ==> {"id":"91","method":"analysis.getHover","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","offset":5772},"clientRequestTime":1596675548859}
[21:59:08] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\jckod\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
[21:59:13] [Analyzer] [Info] ==> {"id":"92","method":"edit.getFixes","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","offset":5507},"clientRequestTime":1596675553311}
[21:59:13] [Analyzer] [Info] ==> {"id":"93","method":"edit.getAssists","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":0,"offset":5507},"clientRequestTime":1596675553312}
[21:59:13] [Analyzer] [Info] ==> {"id":"94","method":"edit.getAvailableRefactorings","params":{"file":"C:\\Projects\\MCC2020\\Frontend\\lib\\pages\\profile\\migrate_data_page.dart","length":0,"offset":5507},"clientRequestTime":1596675553314}
It looks like the server may have crashed before you started the log here. Could you try enabling the analysis server log and reproduce, and see whether there's a better error written there? Thanks!
Had this issue too. Then I restarted vscode, ran flutter clean and now I'm not able to debug
@DanTup I got this from the log
dartanalyzer.txt
@rasmuschristensen can you file a new issue about not being able to debug, and capture a log (using Dart: Capture Logs and unticking Analysis Server but keeping everything else ticked).
Are you still also seeing the analysis server terminating? It's not clear from this log, as it just seems to end without any errors or outstanding analyzer requests.
Before I restarted vscode and enabled the log it terminated, just after upgrading I think. I just tried downgrading to 1.17.5 using the newest 3.13.2 of code at it works just fine
@rasmuschristensen I'm not sure what issue you're seeing. When on v1.20.0 of Flutter and v3.13.2 of the Dart extension, is the analyzer still terminating?
And if you're seeing issues starting debugging, could you file a new issue with a log described above (being unable to debug and the analyzer terminating are likely not related). Thanks!
I got the same issue here. Still happening right now. It was always triggered after I started debugging.
And the crash-related log is like
[2:39:51 PM] [General] [Error] Cannot call write after a stream was destroyed
Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
at doWrite (_stream_writable.js:414:19)
at writeOrBuffer (_stream_writable.js:402:5)
at Socket.Writable.write (_stream_writable.js:302:11)
at b.sendMessage (c:\Users\mingy\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:152985)
at b.sendMessage (c:\Users\mingy\.vscode\extensions\dart-code.dart-code-3.13.2\out\dist\extension.js:1:147394)
at c:\Use…
@elricym can you capture a log using Dart: Capture Logs and leave everything ticked, then reproduce the issue?
Dart-Code-Log-2020-07-02 14-51-19.txt
Thank you @DanTup .
Thanks - I wonder if this may be related to https://github.com/flutter/flutter/issues/46616 / https://github.com/dart-lang/sdk/issues/40348. Since you're both on Windows (which was also where https://github.com/dart-lang/sdk/issues/40348 happened) I'll try to do some testing there.
In case I can't, it might be useful to also get an analyzer instrumentation log when this happens, as that will include a list of the file system watcher events that were fired.
Thanks!
Thanks - I was able to reproduce what I suspect is the same thing, which seems like a repeat of https://github.com/flutter/flutter/issues/46616. There's an open SDK issue at https://github.com/dart-lang/sdk/issues/40348 which I've added some notes and a crash dump to.
I'm (again) also affected by repeating "Dart Analyzer has terminated" messages after upgrading from flutter 1.17.5 to 1.20.x. I already struggled with issue flutter/flutter#46616 some times ago, which was resolved for me by fixes mentioned in that issue. I'm on Windows, too.
@DanTup If you need additional info or logs, I would be glad to provide them.
@szerner https://github.com/dart-lang/sdk/issues/40348 is the issue tracking this. It's in the VM so a bit outside of my area - though I added steps and a crash log there that will hopefully help VM devs track it down. If you have more reliable repro steps than me, please do add them to that issue.
I'm (again) also affected by repeating "Dart Analyzer has terminated" messages after upgrading from flutter 1.17.5 to 1.20.x. I already struggled with issue flutter/flutter#46616 some times ago, which was resolved for me by fixes mentioned in that issue. I'm on Windows, too.
I gave up to use Flutter on Windows. Despite being the most used platform, according to Flutter's Survey, they don't give a ** about us. Even on Mac there are some nasty bugs (specially with Pod - duplicating project structures so the build fails with duplicate classes errors - not sure if is Flutter build problem or Pod problem).
On Linux, Flutter works pretty good and really really fast (VSCode, on the other hand, is more buggy: just the simple action to delete a file freezes it for about 10 seconds (nothing to do with Dart-Code, I guess)).
Today, there is no reliable Flutter development environment.
@JCKodel I understand your frustration, but please watch your tone. If you have issues, please ensure they're filed in the appropriate repositories (constructively) or add to/add 👍 's to existing issues.
My solution:
After reading multiple related issues, I still did not find an effective solution. Later, I checked the analysis server log, as stated in many issues: there is no difference, but I saw this sentence:
[10:29:56 AM] [Analyzer] [Info] Spawning /usr/local/Cellar/dart/2.9.2/libexec/bin/dart with args ["/usr/local/Cellar/dart/2.9.2/libexec/bin/snapshots/analysis_server.dart.snapshot","--client-id=VS-Code","--client-version=3.13.2","--enable-completion-model"]
My instinct told me that it might be the problem caused by this snapshot, so I deleted the entire snapshap folder, so my problem disappeared
我的解决办法:
中文:我在阅读了多个相关的 issue 之后,依旧没有找到有效的解决办法,后来我查看了analysis server log,就像很多 issue 里说的一样:没有什么不同的地方,但是我看到这样一句:
[10:29:56 AM] [Analyzer] [Info] Spawning /usr/local/Cellar/dart/2.9.2/libexec/bin/dart with args ["/usr/local/Cellar/dart/2.9.2/libexec/bin/snapshots/analysis_server.dart.snapshot","--client-id=VS-Code","--client-version=3.13.2","--enable-completion-model"]
直觉告诉我,可能是这个快照导致的问题,于是我删除了整个 snapshap 文件夹,于是,我的问题消失了
My instinct told me that it might be the problem caused by this snapshot, so I deleted the entire snapshap folder, so my problem disappeared
Deleting the snapshot would likely result in us skipping over that SDK and using the next one we found.
It doesn't seem right that we would've been a using Standard Dart SDK for a Flutter project though, so I'd be interested in a full log if that's what's happening for you.
I encountered this problem in a pure dart project. I cant reproduce the issue
@yinxulai
I can no reproduce the issue
I'm not sure if this is intended to mean you can not reproduce, or can now reproduce?
Judging by the comment on https://github.com/dart-lang/sdk/commit/04879fa4cdc2fc173b99472bae186feecc7e08e0 I think the original fix for the issue I noted above (which was frequently triggered by Flutter writing to the build folder, but could've been triggered by non-Flutter file activity too) was lost as part of NNBD changes, so has been re-applied. This might explain the recent increase in reports of this nature.
If anyone can reliable repro this in an SDK that includes https://github.com/dart-lang/sdk/commit/04879fa4cdc2fc173b99472bae186feecc7e08e0 once it rolls into Fluter (or using a nightly/dev Dart SDK that includes it) it would be good to get a crash log.
Closing this as I believe it's recently been fixed in the SDK. If anyone still sees it on a version of the SDK with the change above (which is very recent), please comment on https://github.com/dart-lang/sdk/issues/40348 and if possible supply a crash log.
I'm still encountering the same issue with the latest dart-code and Flutter SDK. If there is any cleanup procedures needs to be done, please let us know. Thank you.
Dart-Code-Log-2020-08-03 17-51-27.txt
@elricym I've just replied over at https://github.com/dart-lang/sdk/issues/40348#issuecomment-689468824. You're currently on the stable release of Flutter which I don't believe has that fix yet.
Most helpful comment
Thanks - I was able to reproduce what I suspect is the same thing, which seems like a repeat of https://github.com/flutter/flutter/issues/46616. There's an open SDK issue at https://github.com/dart-lang/sdk/issues/40348 which I've added some notes and a crash dump to.