Skip to content

fix: delay request if process not ready yet #340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

quyenvsp
Copy link

@quyenvsp quyenvsp commented Jul 4, 2025

Fixes rrousselGit/riverpod#3582 dart-lang/sdk#55281

When custom_lint send request before client process started it will never got response and stuck at analysis.setContextRoots, and block all later request.

e.g:

  • Open project in VSCode with many PINNED files, custom_lint will send many request analysis.setSubscriptions, analysis.setPriorityFiles, analysis.updateContent BEFORE client process started
  • Open project in VSCode and run Debug session immediately, custom_lint will send many request for files changed in build process BEFORE client process started
  • ...

Copy link

vercel bot commented Jul 4, 2025

@quyenvsp is attempting to deploy a commit to the Invertase Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

docs-page bot commented Jul 4, 2025

To view this pull requests documentation preview, visit the following URL:

docs.page/invertase/dart_custom_lint~340

Documentation is deployed and generated using docs.page.

@rrousselGit
Copy link
Collaborator

When custom_lint send request before client process started it will never got response and stuck at analysis.setContextRoots, and block all later request.

It will get a response though.
It's just waiting for the process to start

We can't just ignore those requests. This doesn't seem right.

I lack knowledge about the issue though. What exactly are we trying to fix here?

@quyenvsp
Copy link
Author

quyenvsp commented Jul 5, 2025

Thank you for reply,

It's just waiting for the process to start

it will wait for the process to start, but the problem occurs that the process is terminated before it can responds.

Client Request -> Process start ... -> Process terminated before response (by run flutter pub get/upgrade, start Debug,...) -> New process will start again but old request is bypassed (but still waiting for a response) -> It block setContextRoots of new process

We can't just ignore those requests. This doesn't seem right.

I tested it a lot and it doesn't affect anything. Just make sure versionCheck and setContextRoots respond then custom_lint will work fine. Other requests are not important and will be sent similarly during coding.

But if you feel it is not right, then I will try to test and find a more optimal solution instead of dropping the request.

@rrousselGit
Copy link
Collaborator

it will wait for the process to start, but the problem occurs that the process is terminated before it can responds.

Then rather than silencing those requests, we should abort them when the process is terminated.

@quyenvsp quyenvsp force-pushed the fix/request_wait_forever branch from 6e0b235 to f270e45 Compare July 8, 2025 13:22
@quyenvsp quyenvsp changed the title fix: drop request if process not ready yet fix: delay request if process not ready yet Jul 8, 2025
@@ -127,6 +133,7 @@ class SocketCustomLintServerToClientChannel {
sendAnalyzerPluginRequest(_version.toRequest(const Uuid().v4())),
sendAnalyzerPluginRequest(_contextRoots.toRequest(const Uuid().v4())),
]);
_initialed = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of this. It's a bit of a duplicate compared to fields like _processFuture.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_procesFuture only tells whether the process has run or not (even if it has errors), we need a flag to know that the process has run without errors and the analysis.setContextRoots request has been sent.

The logic I'm going for is that all other requests should be sent after analysis.setContextRoots, to ensure those requests have context, so we need to delay them and send later.

anyway it's a typo, Windows can't write test, I'm installing Linux and will ping you when fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All requests naturally await that the process is initialised. That logic is redundant, as the communication channel already handles it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was sent but in the wrong order, I am sorting them (instead of drop them) in the correct order because any AnalyzerPluginRequest must be sent after analysis.setContextRoots.

before (wrong order):
setSubscriptions1
setSubscriptions2
updateContent1
updateContent2
analysis.setContextRoots
updateContent3
updateContent4

after (setContextRoots must be first):
analysis.setContextRoots
setSubscriptions1
setSubscriptions2
updateContent1
updateContent2
updateContent3
updateContent4


void _sendDelayedRequest() {
for (final request in _delayedRequest) {
unawaited(_handleRequest(request));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of all of this logic if we're unawaiting the requests anyway?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is same _requestSubscription, we just need replay request after delay, so no need to await or handle response. I also added test for this MR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

riverpod_lint didn't show assists (in context menu)
2 participants