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
f3ce9d2f
Unverified
Commit
f3ce9d2f
authored
Feb 29, 2024
by
Lau Ching Jun
Committed by
GitHub
Feb 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make daemon server work on ipv6-only machines. (#144359)
Retry binding on ipv6 if binding on ipv4 failed.
parent
ee6111a7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
5 deletions
+115
-5
daemon.dart
packages/flutter_tools/lib/src/commands/daemon.dart
+19
-5
daemon_test.dart
...lutter_tools/test/general.shard/commands/daemon_test.dart
+96
-0
No files found.
packages/flutter_tools/lib/src/commands/daemon.dart
View file @
f3ce9d2f
...
@@ -73,7 +73,7 @@ class DaemonCommand extends FlutterCommand {
...
@@ -73,7 +73,7 @@ class DaemonCommand extends FlutterCommand {
throwToolExit
(
'Invalid port for `--listen-on-tcp-port`:
$error
'
);
throwToolExit
(
'Invalid port for `--listen-on-tcp-port`:
$error
'
);
}
}
await
_
DaemonServer
(
await
DaemonServer
(
port:
port
,
port:
port
,
logger:
StdoutLogger
(
logger:
StdoutLogger
(
terminal:
globals
.
terminal
,
terminal:
globals
.
terminal
,
...
@@ -100,12 +100,14 @@ class DaemonCommand extends FlutterCommand {
...
@@ -100,12 +100,14 @@ class DaemonCommand extends FlutterCommand {
}
}
}
}
class
_DaemonServer
{
@visibleForTesting
_DaemonServer
({
class
DaemonServer
{
DaemonServer
({
this
.
port
,
this
.
port
,
required
this
.
logger
,
required
this
.
logger
,
this
.
notifyingLogger
,
this
.
notifyingLogger
,
});
@visibleForTesting
Future
<
ServerSocket
>
Function
(
InternetAddress
address
,
int
port
)
bind
=
ServerSocket
.
bind
,
})
:
_bind
=
bind
;
final
int
?
port
;
final
int
?
port
;
...
@@ -115,8 +117,20 @@ class _DaemonServer {
...
@@ -115,8 +117,20 @@ class _DaemonServer {
// Logger that sends the message to the other end of daemon connection.
// Logger that sends the message to the other end of daemon connection.
final
NotifyingLogger
?
notifyingLogger
;
final
NotifyingLogger
?
notifyingLogger
;
final
Future
<
ServerSocket
>
Function
(
InternetAddress
address
,
int
port
)
_bind
;
Future
<
void
>
run
()
async
{
Future
<
void
>
run
()
async
{
final
ServerSocket
serverSocket
=
await
ServerSocket
.
bind
(
InternetAddress
.
loopbackIPv4
,
port
!);
ServerSocket
?
serverSocket
;
try
{
serverSocket
=
await
_bind
(
InternetAddress
.
loopbackIPv4
,
port
!);
}
on
SocketException
{
logger
.
printTrace
(
'Bind on
$port
failed with IPv4, retrying on IPv6'
);
}
// If binding on IPv4 failed, try binding on IPv6.
// Omit try catch here, let the failure fallthrough.
serverSocket
??=
await
_bind
(
InternetAddress
.
loopbackIPv6
,
port
!);
logger
.
printStatus
(
'Daemon server listening on
${serverSocket.port}
'
);
logger
.
printStatus
(
'Daemon server listening on
${serverSocket.port}
'
);
final
StreamSubscription
<
Socket
>
subscription
=
serverSocket
.
listen
(
final
StreamSubscription
<
Socket
>
subscription
=
serverSocket
.
listen
(
...
...
packages/flutter_tools/test/general.shard/commands/daemon_test.dart
0 → 100644
View file @
f3ce9d2f
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/commands/daemon.dart'
;
import
'package:test/fake.dart'
;
import
'../../src/common.dart'
;
void
main
(
)
{
testWithoutContext
(
'binds on ipv4 normally'
,
()
async
{
final
FakeServerSocket
socket
=
FakeServerSocket
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
int
bindCalledTimes
=
0
;
final
List
<
Object
?>
bindAddresses
=
<
Object
?>[];
final
List
<
int
>
bindPorts
=
<
int
>[];
final
DaemonServer
server
=
DaemonServer
(
port:
123
,
logger:
logger
,
bind:
(
Object
?
address
,
int
port
)
async
{
bindCalledTimes
++;
bindAddresses
.
add
(
address
);
bindPorts
.
add
(
port
);
return
socket
;
},
);
await
server
.
run
();
expect
(
bindCalledTimes
,
1
);
expect
(
bindAddresses
,
<
Object
?>[
InternetAddress
.
loopbackIPv4
]);
expect
(
bindPorts
,
<
int
>[
123
]);
});
testWithoutContext
(
'binds on ipv6 if ipv4 failed normally'
,
()
async
{
final
FakeServerSocket
socket
=
FakeServerSocket
();
final
BufferLogger
logger
=
BufferLogger
.
test
();
int
bindCalledTimes
=
0
;
final
List
<
Object
?>
bindAddresses
=
<
Object
?>[];
final
List
<
int
>
bindPorts
=
<
int
>[];
final
DaemonServer
server
=
DaemonServer
(
port:
123
,
logger:
logger
,
bind:
(
Object
?
address
,
int
port
)
async
{
bindCalledTimes
++;
bindAddresses
.
add
(
address
);
bindPorts
.
add
(
port
);
if
(
address
==
InternetAddress
.
loopbackIPv4
)
{
throw
const
SocketException
(
'fail'
);
}
return
socket
;
},
);
await
server
.
run
();
expect
(
bindCalledTimes
,
2
);
expect
(
bindAddresses
,
<
Object
?>[
InternetAddress
.
loopbackIPv4
,
InternetAddress
.
loopbackIPv6
]);
expect
(
bindPorts
,
<
int
>[
123
,
123
]);
});
}
class
FakeServerSocket
extends
Fake
implements
ServerSocket
{
FakeServerSocket
();
@override
int
get
port
=>
1
;
bool
closeCalled
=
false
;
final
StreamController
<
Socket
>
controller
=
StreamController
<
Socket
>();
@override
StreamSubscription
<
Socket
>
listen
(
void
Function
(
Socket
event
)?
onData
,
{
Function
?
onError
,
void
Function
()?
onDone
,
bool
?
cancelOnError
,
})
{
// Close the controller immediately for testing purpose.
scheduleMicrotask
(()
{
controller
.
close
();
});
return
controller
.
stream
.
listen
(
onData
,
onError:
onError
,
onDone:
onDone
,
cancelOnError:
cancelOnError
);
}
@override
Future
<
ServerSocket
>
close
()
async
{
closeCalled
=
true
;
return
this
;
}
}
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