webdev icon indicating copy to clipboard operation
webdev copied to clipboard

Bug: Webdev duplicates app connections for each refresh.

Open schultek opened this issue 9 months ago • 0 comments

The webdev daemon does not properly handle app reconnections. For each page refresh a new app connection is setup while the existing ones are still active. This causes duplicate app connections which quickly pile up after a few refreshes.

The code that causes this:

https://github.com/dart-lang/webdev/blob/697f2f7f56517b0678c6256e0834778905acfc0d/webdev/lib/src/daemon/app_domain.dart#L67

dwds.connectedApps will emit a new appConnection whenever the browser refreshes, even if this app was already handled in webdev. The app will have the same id as an already active app in _appStates[appId], but this is never checked. Therefore all event handlers will be duplicated.


This can be observed simply by printing some logs on the client and refreshing the page:

Steps to reproduce:

  1. dart create bugtest -t web
  2. cd bugtest
  3. webdev daemon (Or launch a dart web debug session from vscode, which uses the daemon)
  4. Add print("Hello Web"); inside the main() in web/main.dart
  5. Go to chrome (should open automatically) and refresh the page multiple times.

Expected:

After each refresh ONE log event is printed to the terminal, e.g. [{"event":"app.log","params":{"appId":"CxpfkG6Rz+5OTXWmy8kREA==","log":"Hello Web\n"}}]

Actual:

After each refresh DUPLICATE log events are printed in the number of past refreshes. E.g. after the 10th refresh, 10 duplicate log events are printed.

schultek avatar Mar 29 '25 19:03 schultek