Skip to content

Commit b999b64

Browse files
authored
feat: fix hang that occurs when hot restarting (#718)
1 parent bf8bbde commit b999b64

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Remove generated status codes.
55
* Remove dependency on `package:archive`.
66
* Move `codec.dart`.
7+
* Work around hang during Flutter hot restart by adding default case handler in _GrpcWebConversionSink.add.
78

89
## 3.2.4
910

lib/src/client/transport/web_streams.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ class _GrpcWebConversionSink implements ChunkedConversionSink<ByteBuffer> {
132132
void add(ByteBuffer chunk) {
133133
_chunkOffset = 0;
134134
final chunkData = chunk.asUint8List();
135+
// in flutter web, when a hot-restart is requested, the code can get stuck
136+
// in the following loop if there is an active streaming call. the
137+
// switch statement is invoked but doesn't match any of the cases. this
138+
// presumably has something to do how enums work across isolates.
139+
// possibly related to https://github.com/dart-lang/sdk/issues/35626.
140+
//
141+
// in any case, adding a default handler to the switch statement
142+
// causes this loop to end in that case, allowing the old isolate
143+
// to shut down and the hot-restart to work properly.
144+
processingLoop:
135145
while (_chunkOffset < chunk.lengthInBytes) {
136146
switch (_state) {
137147
case _GrpcWebParseState.init:
@@ -143,6 +153,9 @@ class _GrpcWebConversionSink implements ChunkedConversionSink<ByteBuffer> {
143153
case _GrpcWebParseState.message:
144154
_parseMessage(chunkData);
145155
break;
156+
default:
157+
// only expected to be hit when hot-restarting, see above
158+
break processingLoop;
146159
}
147160
}
148161
_chunkOffset = 0;

0 commit comments

Comments
 (0)