unsuitable001 / dart_cronet_sample

[SELECTED] Sample project for GSoC '21 - Cronet based HTTP package
https://github.com/google/cronet.dart
MIT License
2 stars 1 forks source link

[Flutter Linux] FormatException if data is fetched for the first time #8

Closed unsuitable001 closed 3 years ago

unsuitable001 commented 3 years ago

[Flutter Linux] FormatException if data is fetched for the first time. But, if data is fetched later, suppose on a button click, there is no such error and data is fetched and displayed accurately.

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: FormatException: Missing extension byte (at offset 2)
#0      _Utf8Decoder.convertChunked (dart:convert-patch/convert_patch.dart:1887:7)
#1      _Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:314:28)
#2      _Utf8ConversionSink.add (dart:convert/string_conversion.dart:310:5)
#3      _ConverterStreamEventSink.add (dart:convert/chunked_conversion.dart:72:18)
#4      _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
#5      _rootRunUnary (dart:async/zone.dart:1362:47)
#6      _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#7      _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#8      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#9      _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#10     _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
#11     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
#12     _rootRun (dart:async/zone.dart:1346:47)
#13     _CustomZone.run (dart:async/zone.dart:1258:19)
#14     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#15     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#16     _rootRun (dart:async/zone.dart:1354:13)
#17     _CustomZone.run (dart:async/zone.dart:1258:19)
#18     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#19     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#20     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
unsuitable001 commented 3 years ago

Edit: I thought that it's only happening on Flutter Linux. But, NO! It's also happening on Dart CLI on Linux. Just the difference is, in Dart CLI, no exception is thrown. Only first few bytes are getting omitted.

ead></head><body><header>
<title>http://info.cern.ch</title>
</header>

(REDACTED)

Notice that ead>. It should be <head> but <h isn't decoded properly.

When using the alternate api (callback based one - introduced in this library), everything gets decoded correctly. This problem only occurs when we're using it like dart:io style API.

In android, both the approach works fine!