Skip to content

UTF8 decoding error when decoding disconnection reason #1825

@matehat

Description

@matehat

I see the following error report from iOS, very occasionally, correlated with other connection issues.

FormatException: FormatException: Missing extension byte (at offset 5)
#0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1855)
#1      Utf8Decoder.convert (dart:convert/utf.dart:351)
#2      Utf8Codec.decode (dart:convert/utf.dart:64)
#3      CupertinoWebSocket._connectionClosed (package:cupertino_http/src/cupertino_web_socket.dart:189)
#4      CupertinoWebSocket._closeConnectionWithError (package:cupertino_http/src/cupertino_web_socket.dart:181)
#5      _FutureListener.handleError (dart:async/future_impl.dart:245)
#6      Future._propagateToListeners.handleError (dart:async/future_impl.dart:963)
#7      Future._propagateToListeners (dart:async/future_impl.dart:984)
#8      Future._completeErrorObject (dart:async/future_impl.dart:741)
#9      Future._asyncCompleteErrorObject.<fn> (dart:async/future_impl.dart:835)
#10      _microtaskLoop (dart:async/schedule_microtask.dart:40)
#11      _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

Looking at the code, decoding the reason is a little risky:

final closeReason = reason == null ? '' : utf8.decode(reason.toList());

Would it be acceptable for it to fallback to '' if the reason is not a decodable utf8 string?

Metadata

Metadata

Assignees

Labels

package:cupertino_httpIssues related to package:cupertino_httptype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions