Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a8ec7646
Unverified
Commit
a8ec7646
authored
May 25, 2021
by
Jonah Williams
Committed by
GitHub
May 25, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] fix top web crasher (#83272)
parent
a217ab60
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
123 additions
and
37 deletions
+123
-37
devfs_web.dart
packages/flutter_tools/lib/src/isolated/devfs_web.dart
+39
-37
devfs_web_test.dart
.../flutter_tools/test/general.shard/web/devfs_web_test.dart
+84
-0
No files found.
packages/flutter_tools/lib/src/isolated/devfs_web.dart
View file @
a8ec7646
...
@@ -660,45 +660,15 @@ class WebDevFS implements DevFS {
...
@@ -660,45 +660,15 @@ class WebDevFS implements DevFS {
Dwds
get
dwds
=>
webAssetServer
.
dwds
;
Dwds
get
dwds
=>
webAssetServer
.
dwds
;
Future
<
DebugConnection
>
_cachedExtensionFuture
;
@visibleForTesting
StreamSubscription
<
void
>
_connectedApps
;
Future
<
DebugConnection
>
cachedExtensionFuture
;
@visibleForTesting
StreamSubscription
<
void
>
connectedApps
;
/// Connect and retrieve the [DebugConnection] for the current application.
/// Connect and retrieve the [DebugConnection] for the current application.
///
/// Only calls [AppConnection.runMain] on the subsequent connections.
Future
<
ConnectionResult
>
connect
(
bool
useDebugExtension
)
{
Future
<
ConnectionResult
>
connect
(
bool
useDebugExtension
)
{
final
Completer
<
ConnectionResult
>
firstConnection
=
return
connectToApplication
(
useDebugExtension
,
this
,
globals
.
logger
,
createVmServiceDelegate
);
Completer
<
ConnectionResult
>();
_connectedApps
=
dwds
.
connectedApps
.
listen
((
AppConnection
appConnection
)
async
{
try
{
final
DebugConnection
debugConnection
=
useDebugExtension
?
await
(
_cachedExtensionFuture
??=
dwds
.
extensionDebugConnections
.
stream
.
first
)
:
await
dwds
.
debugConnection
(
appConnection
);
if
(
firstConnection
.
isCompleted
)
{
appConnection
.
runMain
();
}
else
{
final
vm_service
.
VmService
vmService
=
await
createVmServiceDelegate
(
Uri
.
parse
(
debugConnection
.
uri
),
logger:
globals
.
logger
,
);
firstConnection
.
complete
(
ConnectionResult
(
appConnection
,
debugConnection
,
vmService
));
}
}
on
Exception
catch
(
error
,
stackTrace
)
{
if
(!
firstConnection
.
isCompleted
)
{
firstConnection
.
completeError
(
error
,
stackTrace
);
}
}
},
onError:
(
dynamic
error
,
StackTrace
stackTrace
)
{
globals
.
printError
(
'Unknown error while waiting for debug connection:
$error
\n
$stackTrace
'
);
if
(!
firstConnection
.
isCompleted
)
{
firstConnection
.
completeError
(
error
,
stackTrace
);
}
});
return
firstConnection
.
future
;
}
}
@override
@override
...
@@ -753,7 +723,7 @@ class WebDevFS implements DevFS {
...
@@ -753,7 +723,7 @@ class WebDevFS implements DevFS {
@override
@override
Future
<
void
>
destroy
()
async
{
Future
<
void
>
destroy
()
async
{
await
webAssetServer
.
dispose
();
await
webAssetServer
.
dispose
();
await
_
connectedApps
?.
cancel
();
await
connectedApps
?.
cancel
();
}
}
@override
@override
...
@@ -1068,3 +1038,35 @@ To serve from a subpath "foo" (i.e. http://localhost:8080/foo/ instead of http:/
...
@@ -1068,3 +1038,35 @@ To serve from a subpath "foo" (i.e. http://localhost:8080/foo/ instead of http:/
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
For more information, see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
'''
;
'''
;
/// Connect and retrieve the [DebugConnection] for the current application.
@visibleForTesting
Future
<
ConnectionResult
>
connectToApplication
(
bool
useDebugExtension
,
WebDevFS
devFS
,
Logger
logger
,
Future
<
vm_service
.
VmService
>
Function
(
Uri
,
{
Logger
logger
})
createVmService
)
{
final
Completer
<
ConnectionResult
>
firstConnection
=
Completer
<
ConnectionResult
>();
devFS
.
connectedApps
=
devFS
.
dwds
.
connectedApps
.
listen
((
AppConnection
appConnection
)
async
{
try
{
final
DebugConnection
debugConnection
=
useDebugExtension
?
await
(
devFS
.
cachedExtensionFuture
??=
devFS
.
dwds
.
extensionDebugConnections
.
stream
.
first
)
:
await
devFS
.
dwds
.
debugConnection
(
appConnection
);
if
(!
firstConnection
.
isCompleted
)
{
final
vm_service
.
VmService
vmService
=
await
createVmService
(
Uri
.
parse
(
debugConnection
.
uri
),
logger:
logger
,
);
firstConnection
.
complete
(
ConnectionResult
(
appConnection
,
debugConnection
,
vmService
));
}
}
on
Exception
catch
(
error
,
stackTrace
)
{
if
(!
firstConnection
.
isCompleted
)
{
firstConnection
.
completeError
(
error
,
stackTrace
);
}
}
},
onError:
(
dynamic
error
,
StackTrace
stackTrace
)
{
logger
.
printError
(
'Unknown error while waiting for debug connection:
$error
\n
$stackTrace
'
);
if
(!
firstConnection
.
isCompleted
)
{
firstConnection
.
completeError
(
error
,
stackTrace
);
}
});
return
firstConnection
.
future
;
}
packages/flutter_tools/test/general.shard/web/devfs_web_test.dart
View file @
a8ec7646
...
@@ -4,10 +4,14 @@
...
@@ -4,10 +4,14 @@
// @dart = 2.8
// @dart = 2.8
import
'dart:async'
;
import
'dart:io'
hide
Directory
,
File
;
import
'dart:io'
hide
Directory
,
File
;
import
'package:dwds/dwds.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/artifacts.dart'
;
import
'package:flutter_tools/src/base/common.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/file_system.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/build_info.dart'
;
import
'package:flutter_tools/src/build_system/targets/web.dart'
;
import
'package:flutter_tools/src/build_system/targets/web.dart'
;
...
@@ -19,8 +23,11 @@ import 'package:flutter_tools/src/web/compile.dart';
...
@@ -19,8 +23,11 @@ import 'package:flutter_tools/src/web/compile.dart';
import
'package:package_config/package_config.dart'
;
import
'package:package_config/package_config.dart'
;
import
'package:shelf/shelf.dart'
;
import
'package:shelf/shelf.dart'
;
import
'package:test/fake.dart'
;
import
'package:test/fake.dart'
;
import
'package:vm_service/vm_service.dart'
as
vm_service
;
import
'../../src/common.dart'
;
import
'../../src/common.dart'
;
import
'../../src/context.dart'
;
import
'../../src/fake_vm_services.dart'
;
import
'../../src/testbed.dart'
;
import
'../../src/testbed.dart'
;
const
List
<
int
>
kTransparentImage
=
<
int
>[
const
List
<
int
>
kTransparentImage
=
<
int
>[
...
@@ -1053,6 +1060,48 @@ void main() {
...
@@ -1053,6 +1060,48 @@ void main() {
},
overrides:
<
Type
,
Generator
>{
},
overrides:
<
Type
,
Generator
>{
Artifacts:
()
=>
Artifacts
.
test
(),
Artifacts:
()
=>
Artifacts
.
test
(),
}));
}));
testWithoutContext
(
'connectToApplication completes the future'
,
()
async
{
final
FakeDwds
dwds
=
FakeDwds
();
final
FakeDevFS
devfs
=
FakeDevFS
()..
dwds
=
dwds
;
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
Future
<
void
>
result
=
connectToApplication
(
false
,
devfs
,
logger
,
(
Uri
uri
,
{
Logger
logger
})
async
{
return
FakeVmService
();
});
dwds
.
controller
.
add
(
FakeAppConnection
());
await
expectLater
(
result
,
completes
);
});
testWithoutContext
(
'Multiple runs of connectToApplication does not complete the future more than once'
,
()
async
{
final
FakeDwds
dwds
=
FakeDwds
();
final
FakeDevFS
devfs
=
FakeDevFS
()..
dwds
=
dwds
;
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
Future
<
void
>
result
=
connectToApplication
(
false
,
devfs
,
logger
,
(
Uri
uri
,
{
Logger
logger
})
async
{
return
FakeVmService
();
});
dwds
.
controller
.
add
(
FakeAppConnection
());
dwds
.
controller
.
add
(
FakeAppConnection
());
unawaited
(
dwds
.
controller
.
close
());
await
expectLater
(
result
,
completes
);
});
testWithoutContext
(
'connectToApplication surfaces errors'
,
()
async
{
final
FakeDwds
dwds
=
FakeDwds
();
final
FakeDevFS
devfs
=
FakeDevFS
()..
dwds
=
dwds
;
final
BufferLogger
logger
=
BufferLogger
.
test
();
final
Future
<
void
>
result
=
connectToApplication
(
false
,
devfs
,
logger
,
(
Uri
uri
,
{
Logger
logger
})
async
{
return
FakeVmService
();
});
dwds
.
controller
.
addError
(
Exception
(
'test'
));
await
expectLater
(()
=>
result
,
throwsException
);
});
}
}
class
FakeHttpServer
extends
Fake
implements
HttpServer
{
class
FakeHttpServer
extends
Fake
implements
HttpServer
{
...
@@ -1081,3 +1130,38 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
...
@@ -1081,3 +1130,38 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
return
output
;
return
output
;
}
}
}
}
class
FakeDevFS
extends
Fake
implements
WebDevFS
{
@override
StreamSubscription
<
void
>
connectedApps
;
@override
Future
<
DebugConnection
>
cachedExtensionFuture
;
@override
Dwds
dwds
;
void
dispose
()
{
connectedApps
.
cancel
();
}
}
class
FakeDwds
extends
Fake
implements
Dwds
{
final
StreamController
<
AppConnection
>
controller
=
StreamController
<
AppConnection
>();
@override
Stream
<
AppConnection
>
get
connectedApps
=>
controller
.
stream
;
@override
Future
<
DebugConnection
>
debugConnection
(
AppConnection
appConnection
)
async
{
return
FakeDebugConnection
();
}
}
class
FakeAppConnection
extends
Fake
implements
AppConnection
{}
class
FakeDebugConnection
extends
Fake
implements
DebugConnection
{
@override
String
get
uri
=>
''
;
}
class
FakeVmService
extends
Fake
implements
vm_service
.
VmService
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment