Skip to content

Commit 6e0b235

Browse files
committed
fix: drop request if process not ready yet
1 parent cea1079 commit 6e0b235

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/custom_lint/lib/src/v2/custom_lint_analyzer_plugin.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ class CustomLintServer {
190190

191191
final response =
192192
await clientChannel.sendAnalyzerPluginRequest(request);
193+
// A request was dropped, so nothing to do.
194+
if (response.id.isEmpty) return null;
193195
_analyzerPluginClientChannel.sendJson(response.toJson());
194196
return null;
195197
});

packages/custom_lint/lib/src/v2/server_to_client_channel.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ class SocketCustomLintServerToClientChannel {
7777
final CustomLintServer _server;
7878
final PluginVersionCheckParams _version;
7979
final ServerSocket _serverSocket;
80-
late final Future<Process?> _processFuture;
8180
final CustomLintWorkspace _workspace;
8281

8382
AnalysisSetContextRootsParams _contextRoots;
83+
Future<Process?>? _processFuture;
8484

8585
late final Stream<CustomLintMessage> _messages = _channel.messages
8686
.map((e) => e! as Map<String, Object?>)
@@ -258,6 +258,13 @@ void main(List<String> args) async {
258258
),
259259
);
260260

261+
// Drop all request if process not ready yet
262+
// Because request will never got response and wait forever
263+
if (request is CustomLintRequestAnalyzerPluginRequest &&
264+
(_processFuture == null || await _processFuture == null)) {
265+
return CustomLintResponseAnalyzerPluginResponse(Response('', 0), id: '');
266+
}
267+
261268
await _channel.sendJson(request.toJson());
262269

263270
final response = await matchingResponse;
@@ -296,11 +303,12 @@ void main(List<String> args) async {
296303
_socket.then((value) => value.close()),
297304
_serverSocket.close(),
298305
_channel.close(),
299-
_processFuture.then<void>(
300-
(value) => value?.kill(),
301-
// The process wasn't started. No need to do anything.
302-
onError: (_) {},
303-
),
306+
if (_processFuture != null)
307+
_processFuture!.then<void>(
308+
(value) => value?.kill(),
309+
// The process wasn't started. No need to do anything.
310+
onError: (_) {},
311+
),
304312
]);
305313
}
306314
}

0 commit comments

Comments
 (0)