Skip to content

Commit 0cc2ddd

Browse files
committed
Version 2.14.0-188.5.beta
* Cherry-pick 5f8a9d3 to beta * Cherry-pick fb32ffd to beta
2 parents bd5cd8a + 9eb0b04 commit 0cc2ddd

File tree

10 files changed

+221
-8
lines changed

10 files changed

+221
-8
lines changed

pkg/vm/lib/transformations/type_flow/transformer.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ class CleanupAnnotations extends RecursiveVisitor {
154154
}
155155

156156
bool _keepAnnotation(Expression annotation) {
157-
final constant = (annotation as ConstantExpression).constant;
158-
if (constant is InstanceConstant) {
159-
final cls = constant.classNode;
160-
return (cls == externalNameClass) ||
161-
(cls == pragmaClass) ||
162-
(protobufHandler != null && protobufHandler.usesAnnotationClass(cls));
157+
if (annotation is ConstantExpression) {
158+
final constant = annotation.constant;
159+
if (constant is InstanceConstant) {
160+
final cls = constant.classNode;
161+
return (cls == externalNameClass) ||
162+
(cls == pragmaClass) ||
163+
(protobufHandler != null &&
164+
protobufHandler.usesAnnotationClass(cls));
165+
}
163166
}
164167
return false;
165168
}

runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,15 @@ DART_EXPORT intptr_t TestLeafCallApi(void (*fn)()) {
314314

315315
#endif // defined(TARGET_OS_LINUX)
316316

317+
// Restore default SIGPIPE handler, which is only needed on mac
318+
// since that is the only platform we explicitly ignore it.
319+
// See Platform::Initialize() in platform_macos.cc.
320+
DART_EXPORT void RestoreSIGPIPEHandler() {
321+
#if defined(HOST_OS_MACOS)
322+
signal(SIGPIPE, SIG_DFL);
323+
#endif
324+
}
325+
317326
DART_EXPORT void IGH_MsanUnpoison(void* start, intptr_t length) {
318327
MSAN_UNPOISON(start, length);
319328
}
@@ -418,7 +427,7 @@ void Fatal(char const* file, int line, char const* error) {
418427

419428
#define FATAL(error) Fatal(__FILE__, __LINE__, error)
420429

421-
void SleepOnAnyOS(intptr_t seconds) {
430+
DART_EXPORT void SleepOnAnyOS(intptr_t seconds) {
422431
#if defined(HOST_OS_WINDOWS)
423432
Sleep(1000 * seconds);
424433
#else

runtime/bin/socket_macos.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ static intptr_t Create(const RawAddr& addr) {
4444
FDUtils::SaveErrorAndClose(fd);
4545
return -1;
4646
}
47+
// Don't raise SIGPIPE when attempting to write to a connection which has
48+
// already closed.
49+
int optval = 1;
50+
VOID_NO_RETRY_EXPECTED(
51+
setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval)));
4752
return fd;
4853
}
4954

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2021, 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+
// Tests that SIGPIPE won't terminate websocket client dart app.
6+
7+
import 'dart:async';
8+
import 'dart:convert';
9+
import 'dart:ffi';
10+
import 'dart:io';
11+
12+
import "package:async_helper/async_helper.dart";
13+
import "package:expect/expect.dart";
14+
import 'package:ffi/ffi.dart';
15+
import 'package:path/path.dart' as p;
16+
17+
import '../../../tests/ffi/dylib_utils.dart';
18+
19+
class Isolate extends Opaque {}
20+
21+
abstract class FfiBindings {
22+
static final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
23+
24+
static final RestoreSIGPIPEHandler =
25+
ffiTestFunctions.lookupFunction<Void Function(), void Function()>(
26+
"RestoreSIGPIPEHandler");
27+
static final SleepOnAnyOS = ffiTestFunctions.lookupFunction<
28+
Void Function(IntPtr), void Function(int)>("SleepOnAnyOS");
29+
}
30+
31+
Future<void> main() async {
32+
asyncStart();
33+
34+
final server = await Process.start(Platform.executable, <String>[
35+
p.join(p.dirname(Platform.script.toFilePath()),
36+
"socket_sigpipe_test_server.dart")
37+
]);
38+
final serverPort = Completer<int>();
39+
server.stdout
40+
.transform(utf8.decoder)
41+
.transform(LineSplitter())
42+
.listen((line) {
43+
print('server stdout: $line');
44+
if (!serverPort.isCompleted) {
45+
serverPort.complete(int.parse(line));
46+
}
47+
});
48+
server.stderr
49+
.transform(utf8.decoder)
50+
.transform(LineSplitter())
51+
.listen((data) {
52+
print('server stderr: $data');
53+
});
54+
55+
FfiBindings.RestoreSIGPIPEHandler();
56+
final ws =
57+
await WebSocket.connect('ws://localhost:${await serverPort.future}');
58+
ws.listen((var data) {
59+
print('Got $data');
60+
// Sleep to prevent closed socket events coming through and being handled.
61+
// This way websocket stays open and writing into it should trigger SIGPIPE.
62+
// Unless of course we requested SIGPIPE not to be generated on broken socket
63+
// pipe. This is what this test is testing - that the SIGPIPE is not generated
64+
// on broken socket pipe.
65+
ws.add('foo');
66+
FfiBindings.SleepOnAnyOS(10 /*seconds*/); // give server time to exit
67+
ws.add('baz');
68+
ws.close();
69+
}, onDone: () {
70+
asyncEnd();
71+
}, onError: (e, st) {
72+
Expect.fail('Client websocket failed $e $st');
73+
});
74+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2021, 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+
// Helper server program for socket_sigpipe_test.dart
6+
7+
import "package:expect/expect.dart";
8+
import "dart:async";
9+
import "dart:io";
10+
11+
main() {
12+
HttpServer.bind("127.0.0.1", 0).then((server) {
13+
print(server.port);
14+
server.listen((request) {
15+
WebSocketTransformer.upgrade(request).then((websocket) async {
16+
websocket.add('bar');
17+
await websocket.close();
18+
await server.close();
19+
print('closed');
20+
});
21+
});
22+
});
23+
}

tests/standalone/standalone.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ verbose_gc_to_bmu_test: SkipByDesign # No verbose_gc in product mode
4747
[ $runtime == dart_precompiled ]
4848
http_launch_test: Skip
4949
io/addlatexhash_test: Skip
50+
io/socket_sigpipe_test: SkipByDesign # Spawns server process using Platform.executable
5051
io/wait_for_event_isolate_test: SkipByDesign # Uses mirrors.
5152
io/wait_for_event_microtask_test: SkipByDesign # Uses mirrors.
5253
io/wait_for_event_nested_microtask_test: SkipByDesign # Uses mirrors.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) 2021, 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+
// Tests that SIGPIPE won't terminate websocket client dart app.
6+
7+
import 'dart:async';
8+
import 'dart:convert';
9+
import 'dart:ffi';
10+
import 'dart:io';
11+
12+
import "package:async_helper/async_helper.dart";
13+
import "package:expect/expect.dart";
14+
import 'package:ffi/ffi.dart';
15+
import 'package:path/path.dart' as p;
16+
17+
import '../../../tests/ffi/dylib_utils.dart';
18+
19+
class Isolate extends Opaque {}
20+
21+
abstract class FfiBindings {
22+
static final ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
23+
24+
static final RestoreSIGPIPEHandler =
25+
ffiTestFunctions.lookupFunction<Void Function(), void Function()>(
26+
"RestoreSIGPIPEHandler");
27+
static final SleepOnAnyOS = ffiTestFunctions.lookupFunction<
28+
Void Function(IntPtr), void Function(int)>("SleepOnAnyOS");
29+
}
30+
31+
Future<void> main() async {
32+
asyncStart();
33+
34+
final server = await Process.start(Platform.executable, <String>[
35+
p.join(p.dirname(Platform.script.toFilePath()),
36+
"socket_sigpipe_test_server.dart")
37+
]);
38+
final serverPort = Completer<int>();
39+
server.stdout
40+
.transform(utf8.decoder)
41+
.transform(LineSplitter())
42+
.listen((line) {
43+
print('server stdout: $line');
44+
if (!serverPort.isCompleted) {
45+
serverPort.complete(int.parse(line));
46+
}
47+
});
48+
server.stderr
49+
.transform(utf8.decoder)
50+
.transform(LineSplitter())
51+
.listen((data) {
52+
print('server stderr: $data');
53+
});
54+
55+
FfiBindings.RestoreSIGPIPEHandler();
56+
final ws =
57+
await WebSocket.connect('ws://localhost:${await serverPort.future}');
58+
ws.listen((var data) {
59+
print('Got $data');
60+
// Sleep to prevent closed socket events coming through and being handled.
61+
// This way websocket stays open and writing into it should trigger SIGPIPE.
62+
// Unless of course we requested SIGPIPE not to be generated on broken socket
63+
// pipe. This is what this test is testing - that the SIGPIPE is not generated
64+
// on broken socket pipe.
65+
ws.add('foo');
66+
FfiBindings.SleepOnAnyOS(10 /*seconds*/); // give server time to exit
67+
ws.add('baz');
68+
ws.close();
69+
}, onDone: () {
70+
asyncEnd();
71+
}, onError: (e, st) {
72+
Expect.fail('Client websocket failed $e $st');
73+
});
74+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2021, 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+
// Helper server program for socket_sigpipe_test.dart
6+
7+
import "package:expect/expect.dart";
8+
import "dart:async";
9+
import "dart:io";
10+
11+
main() {
12+
HttpServer.bind("127.0.0.1", 0).then((server) {
13+
print(server.port);
14+
server.listen((request) {
15+
WebSocketTransformer.upgrade(request).then((websocket) async {
16+
websocket.add('bar');
17+
await websocket.close();
18+
await server.close();
19+
print('closed');
20+
});
21+
});
22+
});
23+
}

tests/standalone_2/standalone_2.status

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ verbose_gc_to_bmu_test: SkipByDesign # No verbose_gc in product mode
4747
[ $runtime == dart_precompiled ]
4848
http_launch_test: Skip
4949
io/addlatexhash_test: Skip
50+
io/socket_sigpipe_test: SkipByDesign # Spawns server process using Platform.executable
5051
io/wait_for_event_isolate_test: SkipByDesign # Uses mirrors.
5152
io/wait_for_event_microtask_test: SkipByDesign # Uses mirrors.
5253
io/wait_for_event_nested_microtask_test: SkipByDesign # Uses mirrors.

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ MAJOR 2
2828
MINOR 14
2929
PATCH 0
3030
PRERELEASE 188
31-
PRERELEASE_PATCH 3
31+
PRERELEASE_PATCH 5

0 commit comments

Comments
 (0)