Skip to content

Commit ff05b45

Browse files
a-sivaCommit Queue
authored andcommitted
Address code review comment.
TEST=ci Change-Id: I778069c914146752f1f1e37dfdd11f71bff3e3a3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441860 Commit-Queue: Siva Annamalai <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 0da3d38 commit ff05b45

File tree

4 files changed

+115
-2
lines changed

4 files changed

+115
-2
lines changed

runtime/bin/process_win.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,9 @@ int Process::Exec(Namespace* namespc,
984984
f.Printf("Process::Exec - CreateJobObject failed %d\n", GetLastError());
985985
return -1;
986986
}
987-
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info = {
988-
{{{0, 0}}, {{0, 0}}, 0, 0, 0, 0, 0, 0, 0}, {0}, 0, 0, 0, 0};
987+
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info;
989988
DWORD qresult;
989+
memset(&info, 0, sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION));
990990
if (!QueryInformationJobObject(hjob, JobObjectExtendedLimitInformation, &info,
991991
sizeof(JOBOBJECT_EXTENDED_LIMIT_INFORMATION),
992992
&qresult)) {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
import 'dart:convert';
7+
8+
Future<void> main(List<String> args) async {
9+
if (args[0] == 'child') {
10+
// Get the Dart script file and start the grandchild process.
11+
var scriptFile = new File(
12+
Platform.script.resolve("process_child_script.dart").toFilePath(),
13+
);
14+
var args = <String>[]..addAll([scriptFile.path, 'grandchild']);
15+
var process = await Process.start(Platform.executable, args);
16+
17+
// Read the port number from the grandchild's stdout stream.
18+
final portNumber = await process.stdout.transform(utf8.decoder).first;
19+
20+
// Relay the port number to the parent process by printing it.
21+
print('${portNumber.trim()}');
22+
23+
// The child process can exit now.
24+
exit(0);
25+
} else {
26+
// Grand child process code.
27+
28+
// Create a server socket and bind it to a random port.
29+
final server = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
30+
31+
// Print the port number to stdout so that it is relayed by the child
32+
// to the parent process and it can read it.
33+
print('${server.port}');
34+
35+
// Now listen for incoming connections, this will confirm to the parent
36+
// that the grandchild is still alive after the child exits.
37+
await for (var socket in server) {
38+
// Listen for data from the client.
39+
socket.listen(
40+
(data) {
41+
final message = utf8.decode(data);
42+
},
43+
onDone: () {
44+
server.close();
45+
exit(0);
46+
},
47+
onError: (error) {
48+
server.close();
49+
exit(1);
50+
},
51+
);
52+
}
53+
}
54+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
// OtherResources=process_child_script.dart
6+
7+
import "package:expect/expect.dart";
8+
import 'package:path/path.dart';
9+
10+
import 'dart:io';
11+
import 'dart:convert';
12+
13+
Future<void> main(List<String> args) async {
14+
// Get the Dart script file for the child process and start the child
15+
// process.
16+
var scriptFile = new File(
17+
Platform.script.resolve("process_child_script.dart").toFilePath(),
18+
);
19+
var args = <String>[]..addAll([scriptFile.path, 'child']);
20+
var process = await Process.start(Platform.executable, args);
21+
22+
// Listen to the child's stdout to get the relayed port number of
23+
// the grand child process.
24+
final portString = await process.stdout.transform(utf8.decoder).first;
25+
final port = int.parse(portString);
26+
27+
print('Received grandchild port $port from child. Child should now exit.');
28+
var exitCode = await process.exitCode;
29+
Expect.equals(0, exitCode);
30+
31+
// Now that the child has exited, connect to the grandchild to make
32+
// sure it is still running and has not exited because the child exited.
33+
try {
34+
// Connect to the grandchild's server socket.
35+
final socket = await Socket.connect(InternetAddress.loopbackIPv4, port);
36+
print('Parent: Connected to grandchild.');
37+
38+
// Send messages to the grandchild.
39+
print('Parent: Sending messages...');
40+
socket.writeln('Hello from the parent!');
41+
await Future.delayed(Duration(seconds: 1));
42+
socket.writeln('How are you?');
43+
await Future.delayed(Duration(seconds: 1));
44+
socket.writeln('Closing the connection.');
45+
46+
// Close the connection.
47+
await socket.close();
48+
print('Parent: Disconnected from grandchild.');
49+
} on SocketException catch (e) {
50+
// If we are unable to connect to the grandchild process it means
51+
// the grandchild process has exited and so this would be an error.
52+
print('Parent: Could not connect to grandchild: $e');
53+
Expect.equals(0, 1); // Force an error.
54+
}
55+
56+
print('Parent: Exiting.');
57+
exit(0);
58+
}

tests/standalone/standalone_kernel.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ io/http_response_deadline_test: Skip # Flaky.
4949
io/http_reuse_server_port_test: Skip # Flaky.
5050
io/http_server_close_response_after_error_test: Skip # Flaky.
5151
io/http_shutdown_test: Skip # Flaky.
52+
io/process_child_test: Skip # The test does not exercise the exec path on AOT
5253
io/raw_datagram_socket_test: Skip # Flaky.
5354
io/raw_secure_server_closing_test: Skip # Flaky
5455
io/raw_socket_test: Crash

0 commit comments

Comments
 (0)