dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.03k stars 1.55k forks source link

[dart2js] improve deferred loading error reporting #55277

Open sigmundch opened 5 months ago

sigmundch commented 5 months ago

An issue was filed in the flutter repro with lots of details of an interesting version mismatch scenario: https://github.com/flutter/flutter/issues/145203

The issue is namely requesting better feedback to help investigate when this is happening.

sigmundch commented 5 months ago

@Miiite - in your investigation, did you see any DeferredLoadException messages being thrown?

The dart2js compiler currently tracks and event-log when deferred loading is taking place. Internal customers have used this log data to diagnose difficult loading errors (sometimes similar in nature of trying to figure out what brought the application to a bad state, like you did).

First thing I'd like to make sure is that this event log is already available to you. Today this event-log is attached to the error that is thrown when a deferred load fails, so we hope it is.

Second thing is to study what additional data would be sufficient to help in this kind of diagnosis. We currently log a lot of details about the state of the loading process, but I don't believe we include a reason for retries as you suggested.

rakudrama commented 5 months ago

Is the error because the second version of the app has been redeployed in the same server directory, overwriting the resources needed by running copies of the first version of the app? Typically web apps are deployed in versioned directories so that multiple versions can be executing in client browsers at the same time.

sigmundch commented 5 months ago

I should have mentioned https://github.com/flutter/flutter/issues/127459, too. Other users have requested a versioning strategy directly in how the compiler generates requests (e.g. adding hashes to the file-names or to the requests somehow).

My recommendation has been to address this as a serving infrastructure solution, like @rakudrama mentions above (see also https://github.com/flutter/flutter/issues/127459#issuecomment-1570515677). This is what many large applications using Dart do today already. It also helps them to clarefully roll out new versions incrementally and not to all users at once.

If we believe a client-based solution is preferable, my recommendation would be to first refactor the script load management logic out of the SDK and into a package attached by the application. This then allows developers to update the loading strategy more easily if they so desire.