Skip to content

Commit 2277e34

Browse files
Jonah WilliamsNoamDev
authored andcommitted
Expose enable-service-port-fallback switch (flutter#16366)
1 parent 7453c28 commit 2277e34

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

common/settings.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ struct Settings {
122122
// the VM service.
123123
bool disable_service_auth_codes = true;
124124

125+
// Determine whether the vmservice should fallback to automatic port selection
126+
// after failing to bind to a specified port.
127+
bool enable_service_port_fallback = false;
128+
125129
// Font settings
126130
bool use_test_fonts = false;
127131

runtime/dart_isolate.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,9 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
625625
tonic::DartState::HandleLibraryTag, // embedder library tag handler
626626
false, // disable websocket origin check
627627
settings.disable_service_auth_codes, // disable VM service auth codes
628-
error // error (out)
628+
settings.enable_service_port_fallback, // enable fallback to port 0
629+
// when bind fails.
630+
error // error (out)
629631
)) {
630632
// Error is populated by call to startup.
631633
FML_DLOG(ERROR) << *error;

runtime/dart_service_isolate.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ bool DartServiceIsolate::Startup(std::string server_ip,
130130
Dart_LibraryTagHandler embedder_tag_handler,
131131
bool disable_origin_check,
132132
bool disable_service_auth_codes,
133+
bool enable_service_port_fallback,
133134
char** error) {
134135
Dart_Isolate isolate = Dart_CurrentIsolate();
135136
FML_CHECK(isolate);
@@ -196,6 +197,9 @@ bool DartServiceIsolate::Startup(std::string server_ip,
196197
Dart_SetField(library, Dart_NewStringFromCString("_authCodesDisabled"),
197198
Dart_NewBoolean(disable_service_auth_codes));
198199
SHUTDOWN_ON_ERROR(result);
200+
result = Dart_SetField(
201+
library, Dart_NewStringFromCString("_enableServicePortFallback"),
202+
Dart_NewBoolean(enable_service_port_fallback));
199203
return true;
200204
}
201205

runtime/dart_service_isolate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DartServiceIsolate {
2626
Dart_LibraryTagHandler embedder_tag_handler,
2727
bool disable_origin_check,
2828
bool disable_service_auth_codes,
29+
bool enable_service_port_fallback,
2930
char** error);
3031

3132
using CallbackHandle = ptrdiff_t;

shell/common/switches.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
242242
settings.disable_service_auth_codes =
243243
command_line.HasOption(FlagForSwitch(Switch::DisableServiceAuthCodes));
244244

245+
// Allow fallback to automatic port selection if binding to a specified port
246+
// fails.
247+
settings.enable_service_port_fallback =
248+
command_line.HasOption(FlagForSwitch(Switch::EnableServicePortFallback));
249+
245250
// Checked mode overrides.
246251
settings.disable_dart_asserts =
247252
command_line.HasOption(FlagForSwitch(Switch::DisableDartAsserts));

shell/common/switches.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ DEF_SWITCH(DisableServiceAuthCodes,
112112
"disable-service-auth-codes",
113113
"Disable the requirement for authentication codes for communicating"
114114
" with the VM service.")
115+
DEF_SWITCH(EnableServicePortFallback,
116+
"enable-service-port-fallback",
117+
"Allow the VM service to fallback to automatic port selection if"
118+
" binding to a specified port fails.")
115119
DEF_SWITCH(StartPaused,
116120
"start-paused",
117121
"Start the application paused in the Dart debugger.")

0 commit comments

Comments
 (0)