Skip to content

Commit

Permalink
feat: fix hang that occurs when hot restarting (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
galenwarren authored Jul 17, 2024
1 parent bf8bbde commit b999b64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Remove generated status codes.
* Remove dependency on `package:archive`.
* Move `codec.dart`.
* Work around hang during Flutter hot restart by adding default case handler in _GrpcWebConversionSink.add.

## 3.2.4

Expand Down
13 changes: 13 additions & 0 deletions lib/src/client/transport/web_streams.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ class _GrpcWebConversionSink implements ChunkedConversionSink<ByteBuffer> {
void add(ByteBuffer chunk) {
_chunkOffset = 0;
final chunkData = chunk.asUint8List();
// in flutter web, when a hot-restart is requested, the code can get stuck
// in the following loop if there is an active streaming call. the
// switch statement is invoked but doesn't match any of the cases. this
// presumably has something to do how enums work across isolates.
// possibly related to https://github.com/dart-lang/sdk/issues/35626.
//
// in any case, adding a default handler to the switch statement
// causes this loop to end in that case, allowing the old isolate
// to shut down and the hot-restart to work properly.
processingLoop:
while (_chunkOffset < chunk.lengthInBytes) {
switch (_state) {
case _GrpcWebParseState.init:
Expand All @@ -143,6 +153,9 @@ class _GrpcWebConversionSink implements ChunkedConversionSink<ByteBuffer> {
case _GrpcWebParseState.message:
_parseMessage(chunkData);
break;
default:
// only expected to be hit when hot-restarting, see above
break processingLoop;
}
}
_chunkOffset = 0;
Expand Down

0 comments on commit b999b64

Please sign in to comment.