From 2e835da9b489659ec5e8cdbbcf3c760bf4db0419 Mon Sep 17 00:00:00 2001 From: Curtis Caulfield Date: Thu, 12 Sep 2024 00:31:49 +0100 Subject: [PATCH] Use `@pragma('vm:awaiter-link')` for better stacktraces --- dio/lib/src/cancel_token.dart | 1 + dio/lib/src/compute/compute_io.dart | 1 + dio/lib/src/dio/dio_for_native.dart | 1 + dio/lib/src/utils.dart | 1 + dio/test/utils.dart | 1 + dio_test/lib/src/test/cancellation_tests.dart | 2 ++ dio_test/lib/src/test/download_tests.dart | 1 + dio_test/lib/src/test/timeout_tests.dart | 1 + .../compatibility_layer/lib/src/conversion_layer_adapter.dart | 1 + plugins/http2_adapter/lib/src/connection_manager_imp.dart | 1 + plugins/http2_adapter/lib/src/http2_adapter.dart | 1 + .../native_dio_adapter/lib/src/conversion_layer_adapter.dart | 1 + plugins/web_adapter/lib/src/adapter.dart | 1 + 13 files changed, 14 insertions(+) diff --git a/dio/lib/src/cancel_token.dart b/dio/lib/src/cancel_token.dart index 2dfa656ad..043f3e849 100644 --- a/dio/lib/src/cancel_token.dart +++ b/dio/lib/src/cancel_token.dart @@ -12,6 +12,7 @@ import 'options.dart'; class CancelToken { CancelToken(); + @pragma('vm:awaiter-link') final Completer _completer = Completer(); /// Whether the [error] is thrown by [cancel]. diff --git a/dio/lib/src/compute/compute_io.dart b/dio/lib/src/compute/compute_io.dart index 6bf0a53d8..ec5a935fd 100644 --- a/dio/lib/src/compute/compute_io.dart +++ b/dio/lib/src/compute/compute_io.dart @@ -44,6 +44,7 @@ Future compute( Timeline.finishSync(); } + @pragma('vm:awaiter-link') final Completer completer = Completer(); port.handler = (dynamic msg) { timeEndAndCleanup(); diff --git a/dio/lib/src/dio/dio_for_native.dart b/dio/lib/src/dio/dio_for_native.dart index 1e016935d..aa97db8dc 100644 --- a/dio/lib/src/dio/dio_for_native.dart +++ b/dio/lib/src/dio/dio_for_native.dart @@ -98,6 +98,7 @@ class DioForNative with DioMixin implements Dio { RandomAccessFile raf = file.openSync(mode: FileMode.write); // Create a Completer to notify the success/error state. + @pragma('vm:awaiter-link') final completer = Completer(); int received = 0; diff --git a/dio/lib/src/utils.dart b/dio/lib/src/utils.dart index 06d5aa94e..4038baa1f 100644 --- a/dio/lib/src/utils.dart +++ b/dio/lib/src/utils.dart @@ -22,6 +22,7 @@ const kReleaseMode = bool.fromEnvironment('dart.vm.product'); /// [stream] is done. Unlike [store], [sink] remains open after [stream] is /// done. Future writeStreamToSink(Stream stream, EventSink sink) { + @pragma('vm:awaiter-link') final completer = Completer(); stream.listen( sink.add, diff --git a/dio/test/utils.dart b/dio/test/utils.dart index 511a06464..2e11084f2 100644 --- a/dio/test/utils.dart +++ b/dio/test/utils.dart @@ -186,6 +186,7 @@ class ByteStream extends StreamView> { /// Collects the data of this stream in a [Uint8List]. Future toBytes() { + @pragma('vm:awaiter-link') final completer = Completer(); final sink = ByteConversionSink.withCallback( (bytes) => completer.complete(Uint8List.fromList(bytes)), diff --git a/dio_test/lib/src/test/cancellation_tests.dart b/dio_test/lib/src/test/cancellation_tests.dart index ad7579eef..5acfadfe4 100644 --- a/dio_test/lib/src/test/cancellation_tests.dart +++ b/dio_test/lib/src/test/cancellation_tests.dart @@ -48,7 +48,9 @@ void cancellationTests( test('cancel multiple requests with single token', () async { final token = CancelToken(); + @pragma('vm:awaiter-link') final receiveSuccess1 = Completer(); + @pragma('vm:awaiter-link') final receiveSuccess2 = Completer(); final futures = [ dio.get( diff --git a/dio_test/lib/src/test/download_tests.dart b/dio_test/lib/src/test/download_tests.dart index f81e30a9c..cf40dc852 100644 --- a/dio_test/lib/src/test/download_tests.dart +++ b/dio_test/lib/src/test/download_tests.dart @@ -65,6 +65,7 @@ void downloadTests( cancelToken.cancel(); }); + @pragma('vm:awaiter-link') final completer = Completer(); res.data!.stream.listen( (event) {}, diff --git a/dio_test/lib/src/test/timeout_tests.dart b/dio_test/lib/src/test/timeout_tests.dart index 80bdd52cd..b82b44a5f 100644 --- a/dio_test/lib/src/test/timeout_tests.dart +++ b/dio_test/lib/src/test/timeout_tests.dart @@ -44,6 +44,7 @@ void timeoutTests( 'with streamed response', () async { dio.options.receiveTimeout = const Duration(seconds: 1); + @pragma('vm:awaiter-link') final completer = Completer(); final streamedResponse = await dio.get( '/drip', diff --git a/plugins/compatibility_layer/lib/src/conversion_layer_adapter.dart b/plugins/compatibility_layer/lib/src/conversion_layer_adapter.dart index 87ec81e1a..e6c6f13bf 100644 --- a/plugins/compatibility_layer/lib/src/conversion_layer_adapter.dart +++ b/plugins/compatibility_layer/lib/src/conversion_layer_adapter.dart @@ -53,6 +53,7 @@ class ConversionLayerAdapter implements HttpClientAdapter { options.method, options.uri, ); + @pragma('vm:awaiter-link') final completer = Completer(); final sink = ByteConversionSink.withCallback( (bytes) => completer.complete( diff --git a/plugins/http2_adapter/lib/src/connection_manager_imp.dart b/plugins/http2_adapter/lib/src/connection_manager_imp.dart index aeec77a26..2ce46cc62 100644 --- a/plugins/http2_adapter/lib/src/connection_manager_imp.dart +++ b/plugins/http2_adapter/lib/src/connection_manager_imp.dart @@ -194,6 +194,7 @@ class _ConnectionManager implements ConnectionManager { proxySocket.write(crlf); proxySocket.write(crlf); + @pragma('vm:awaiter-link') final completerProxyInitialization = Completer(); Never onProxyError(Object? error, StackTrace stackTrace) { diff --git a/plugins/http2_adapter/lib/src/http2_adapter.dart b/plugins/http2_adapter/lib/src/http2_adapter.dart index b4d758326..fbbec1484 100644 --- a/plugins/http2_adapter/lib/src/http2_adapter.dart +++ b/plugins/http2_adapter/lib/src/http2_adapter.dart @@ -162,6 +162,7 @@ class Http2Adapter implements HttpClientAdapter { final responseSink = StreamController(); final responseHeaders = Headers(); + @pragma('vm:awaiter-link') final responseCompleter = Completer(); late StreamSubscription responseSubscription; bool needRedirect = false; diff --git a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart index 42f07b805..46ab031b0 100644 --- a/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart +++ b/plugins/native_dio_adapter/lib/src/conversion_layer_adapter.dart @@ -54,6 +54,7 @@ class ConversionLayerAdapter implements HttpClientAdapter { request.maxRedirects = options.maxRedirects; if (requestStream != null) { + @pragma('vm:awaiter-link') final completer = Completer(); final sink = ByteConversionSink.withCallback( (bytes) => completer.complete( diff --git a/plugins/web_adapter/lib/src/adapter.dart b/plugins/web_adapter/lib/src/adapter.dart index cec2d2c47..e4ae982ce 100644 --- a/plugins/web_adapter/lib/src/adapter.dart +++ b/plugins/web_adapter/lib/src/adapter.dart @@ -61,6 +61,7 @@ class BrowserHttpClientAdapter implements HttpClientAdapter { final xhrTimeout = (connectTimeout + receiveTimeout).inMilliseconds; xhr.timeout = xhrTimeout; + @pragma('vm:awaiter-link') final completer = Completer(); xhr.onLoad.first.then((_) {