Skip to content

Commit

Permalink
Version 2.13.3
Browse files Browse the repository at this point in the history
* Cherry-pick 30321de to stable
* Cherry-pick f827c53 to stable
* Cherry-pick 05e5427 to stable
  • Loading branch information
athomas committed Jun 9, 2021
2 parents fdce7a8 + 74b8195 commit 516eb3b
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.13.2 - 2021-06-09
## 2.13.3 - 2021-06-10

This is a patch release that fixes:

Expand Down
2 changes: 2 additions & 0 deletions runtime/bin/file_system_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
namespace dart {
namespace bin {

bool FileSystemWatcher::delayed_filewatch_callback_ = false;

void FUNCTION_NAME(FileSystemWatcher_IsSupported)(Dart_NativeArguments args) {
Dart_SetBooleanReturnValue(args, FileSystemWatcher::IsSupported());
}
Expand Down
8 changes: 8 additions & 0 deletions runtime/bin/file_system_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@ class FileSystemWatcher {
static intptr_t GetSocketId(intptr_t id, intptr_t path_id);
static Dart_Handle ReadEvents(intptr_t id, intptr_t path_id);

static void set_delayed_filewatch_callback(bool value) {
delayed_filewatch_callback_ = value;
}
static bool delayed_filewatch_callback() {
return delayed_filewatch_callback_;
}

private:
static bool delayed_filewatch_callback_;
DISALLOW_COPY_AND_ASSIGN(FileSystemWatcher);
};

Expand Down
29 changes: 17 additions & 12 deletions runtime/bin/file_system_watcher_macos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class FSEventsWatcher {
int write_fd,
bool recursive)
: watcher_(watcher),
ready_(false),
base_path_length_(strlen(base_path)),
path_ref_(CFStringCreateWithCString(NULL,
base_path,
Expand All @@ -74,9 +73,14 @@ class FSEventsWatcher {
}

~Node() {
Stop();
// This is invoked outside of [Callback] execution because
// [context.release] callback is invoked when [FSEventStream] is
// deallocated, the same [FSEventStream] that [Callback] gets a reference
// to during its execution. [Callback] holding a reference prevents stream
// from deallocation.
close(write_fd_);
CFRelease(path_ref_);
watcher_ = nullptr; // this is to catch access-after-free in Callback
}

void set_ref(FSEventStreamRef ref) { ref_ = ref; }
Expand All @@ -85,6 +89,9 @@ class FSEventsWatcher {
FSEventStreamContext context;
memset(&context, 0, sizeof(context));
context.info = reinterpret_cast<void*>(this);
context.release = [](const void* info) {
delete static_cast<const Node*>(info);
};
CFArrayRef array = CFArrayCreate(
NULL, reinterpret_cast<const void**>(&path_ref_), 1, NULL);
FSEventStreamRef ref = FSEventStreamCreate(
Expand All @@ -93,7 +100,6 @@ class FSEventsWatcher {
CFRelease(array);

set_ref(ref);
ready_.store(true, std::memory_order_release);

FSEventStreamScheduleWithRunLoop(ref_, watcher_->run_loop_,
kCFRunLoopDefaultMode);
Expand All @@ -103,23 +109,19 @@ class FSEventsWatcher {
}

void Stop() {
ASSERT(ready_);
FSEventStreamStop(ref_);
FSEventStreamInvalidate(ref_);
FSEventStreamRelease(ref_);
ready_.store(false, std::memory_order_release);
}

FSEventsWatcher* watcher() const { return watcher_; }
bool ready() const { return ready_.load(std::memory_order_acquire); }
intptr_t base_path_length() const { return base_path_length_; }
int read_fd() const { return read_fd_; }
int write_fd() const { return write_fd_; }
bool recursive() const { return recursive_; }

private:
FSEventsWatcher* watcher_;
std::atomic<bool> ready_;
intptr_t base_path_length_;
CFStringRef path_ref_;
int read_fd_;
Expand Down Expand Up @@ -218,12 +220,15 @@ class FSEventsWatcher {
void* event_paths,
const FSEventStreamEventFlags event_flags[],
const FSEventStreamEventId event_ids[]) {
Node* node = reinterpret_cast<Node*>(client);
if (FileSystemWatcher::delayed_filewatch_callback()) {
// Used in tests to highlight race between callback invocation
// and unwatching the file path, Node destruction
TimerUtils::Sleep(1000 /* ms */);
}
Node* node = static_cast<Node*>(client);
RELEASE_ASSERT(node->watcher() != nullptr);
ASSERT(Thread::Compare(node->watcher()->threadId_,
Thread::GetCurrentThreadId()));
if (!node->ready()) {
return;
}
for (size_t i = 0; i < num_events; i++) {
char* path = reinterpret_cast<char**>(event_paths)[i];
FSEvent event;
Expand Down Expand Up @@ -274,7 +279,7 @@ intptr_t FileSystemWatcher::WatchPath(intptr_t id,

void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
USE(id);
delete reinterpret_cast<FSEventsWatcher::Node*>(path_id);
reinterpret_cast<FSEventsWatcher::Node*>(path_id)->Stop();
}

intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
Expand Down
4 changes: 4 additions & 0 deletions runtime/bin/main_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "bin/dartdev_isolate.h"
#include "bin/error_exit.h"
#include "bin/file_system_watcher.h"
#include "bin/options.h"
#include "bin/platform.h"
#include "bin/utils.h"
Expand Down Expand Up @@ -472,6 +473,9 @@ bool Options::ParseArguments(int argc,
Options::long_ssl_cert_evaluation());
#endif // !defined(DART_IO_SECURE_SOCKET_DISABLED)

FileSystemWatcher::set_delayed_filewatch_callback(
Options::delayed_filewatch_callback());

// The arguments to the VM are at positions 1 through i-1 in argv.
Platform::SetExecutableArguments(i, argv);

Expand Down
4 changes: 3 additions & 1 deletion runtime/bin/main_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ namespace bin {
V(suppress_core_dump, suppress_core_dump) \
V(enable_service_port_fallback, enable_service_port_fallback) \
V(disable_dart_dev, disable_dart_dev) \
V(long_ssl_cert_evaluation, long_ssl_cert_evaluation)
V(long_ssl_cert_evaluation, long_ssl_cert_evaluation) \
V(bypass_trusting_system_roots, bypass_trusting_system_roots) \
V(delayed_filewatch_callback, delayed_filewatch_callback)

// Boolean flags that have a short form.
#define SHORT_BOOL_OPTIONS_LIST(V) \
Expand Down
6 changes: 3 additions & 3 deletions runtime/tests/vm/dart/transferable_throws_oom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main() {
// Attempt to create total 1tb uint8list which should fail on 32 and 64-bit
// platforms.
final bytes100MB = Uint8List(100 * 1024 * 1024);
final total1TB = List<Uint8List>.filled(10000, bytes100MB);
// Try to make a 1 TB transferable.
Expect.throws(() => TransferableTypedData.fromList(total1TB));
final total1PB = List<Uint8List>.filled(10 * 1000 * 1000, bytes100MB);
// Try to make a 1 PB transferable.
Expect.throws(() => TransferableTypedData.fromList(total1PB));
}
6 changes: 3 additions & 3 deletions runtime/tests/vm/dart_2/transferable_throws_oom_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main() {
// Attempt to create total 1tb uint8list which should fail on 32 and 64-bit
// platforms.
final bytes100MB = Uint8List(100 * 1024 * 1024);
final total1TB = List<Uint8List>.filled(10000, bytes100MB);
// Try to make a 1 TB transferable.
Expect.throws(() => TransferableTypedData.fromList(total1TB));
final total1PB = List<Uint8List>.filled(10 * 1000 * 1000, bytes100MB);
// Try to make a 1 PB transferable.
Expect.throws(() => TransferableTypedData.fromList(total1PB));
}
40 changes: 40 additions & 0 deletions tests/standalone/io/file_system_watcher_large_set_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--delayed-filewatch-callback --enable-isolate-groups --experimental-enable-isolate-groups-jit
// VMOptions=--delayed-filewatch-callback --no-enable-isolate-groups

// Verifies that cancelling subscription from inside of the event handler
// works as expected, does not result in crash or hang.

import "dart:async";
import "dart:io";

import "package:path/path.dart";

final completer = Completer<void>();
late StreamSubscription subscription;

void handleWatchEvent(event) {
if (event is FileSystemCreateEvent && event.path.endsWith('txt')) {
subscription.cancel();
completer.complete();
}
}

void main() async {
if (!FileSystemEntity.isWatchSupported) return;
final dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
final watcher = dir.watch();
subscription = watcher.listen(handleWatchEvent);

print('watching ${dir.path}');
for (int i = 0; i < 1000; i++) {
File(join(dir.path, 'file_$i.txt')).createSync();
}
await completer.future;
try {
dir.deleteSync(recursive: true);
} catch (_) {}
}
40 changes: 40 additions & 0 deletions tests/standalone_2/io/file_system_watcher_large_set_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// VMOptions=--delayed-filewatch-callback --enable-isolate-groups --experimental-enable-isolate-groups-jit
// VMOptions=--delayed-filewatch-callback --no-enable-isolate-groups

// Verifies that cancelling subscription from inside of the event handler
// works as expected, does not result in crash or hang.

import "dart:async";
import "dart:io";

import "package:path/path.dart";

final completer = Completer<void>();
var subscription;

void handleWatchEvent(event) {
if (event is FileSystemCreateEvent && event.path.endsWith('txt')) {
subscription.cancel();
completer.complete();
}
}

void main() async {
if (!FileSystemEntity.isWatchSupported) return;
final dir = Directory.systemTemp.createTempSync('dart_file_system_watcher');
final watcher = dir.watch();
subscription = watcher.listen(handleWatchEvent);

print('watching ${dir.path}');
for (int i = 0; i < 1000; i++) {
File(join(dir.path, 'file_$i.txt')).createSync();
}
await completer.future;
try {
dir.deleteSync(recursive: true);
} catch (_) {}
}
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
CHANNEL stable
MAJOR 2
MINOR 13
PATCH 2
PATCH 3
PRERELEASE 0
PRERELEASE_PATCH 0

0 comments on commit 516eb3b

Please sign in to comment.