-
Notifications
You must be signed in to change notification settings - Fork 75
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
fix devtools processes #44
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Charly6596 this looks good to me, regarding the flutter process versus our own, tbh if flutter is already doing it, I'm not sure why try and take control of it rather than just track the url it creates in the devtools module i.e option 3.
What would be the benefit of method 2 i.e. creating it and then passing it to the run command? not to say that there'd be no value I'm just not sure what it would be
function M.stop() | ||
if devtools_pid then | ||
local uv = vim.loop | ||
uv.kill(devtools_pid, uv.constants.SIGTERM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will killing the job via it's PID cause any side effects for plenary
jobs? they have a close
method which I'm sure does this at some point under the hood I'm just wondering what they do if the underlying process dies outside of it's control.
It's not a big deal since this is on close but will the user see any messy errors on vim leave?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually yes, if you execute the stop function and the server is running you can see the errors (not if exiting)
lua require('flutter-tools.dev_tools').stop()
Error executing vim.schedule lua callback: /home/charly/.config/nvim/lua/flutter-tools/dev_tools.lua:52: bad argument #1 to 'ipairs' (table expected, got strin
g)
We get the same behaviour if we call job:shutdown()
inside M.stop()
and kill the process in our on_exit
handle and that is because they pass nil
to the self._user_on_stdout
and self._user_on_stderr
functions here
The readers are linked to self._user_on_stdout
and self._stderr_reader
So we would avoid getting that message if we check for nil
at the start of our handle_error
and handle_start
functions.
In their specification they don't specify the data
parameter as nullable so I think we should open an issue for that
I'm assuming Job:shutdown
is being called when we kill the dart devtools process.
If we close the job using :shutdown, devtools is still there, that's why I kill the process. Maybe there is another way, but I couldn't figure out.
By the way, if we do job:shutdown
before killing the process, it takes way more time to close neovim, whereas I can't notice any slowdown if we kill directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I check the error message it says that a string was received, so, errr, what I said applies for executing job:shutdown , maybe my assumption is wrong and they don't call it when devtools dies, will check that out later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, just checked, here's the result
- If we kill the process directly, we get the following in the on_stderr function (second message, we would need to check if the
data
parameter is a table, otherwise ignore it)
- If we do
job:shutdown
before killing the process, we getnil
in both functions:
Error executing vim.schedule lua callback: /home/charly/.config/nvim/lua/flutter-tools/dev_tools.lua:36: attempt to get length of local 'data' (a nil value)
So if you agree with me, I will ignore values that are not tables in the handle_error
function and it should work. The problem: our job is exiting with an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure I follow tbh. So using Job:shutdown
errors? even if the we haven't killed the process? is it possible to just check if the module variable pub_get_job
exists and if so use shutdown
i.e. we started the process so we end it cleanly with plenary
's method if there is no job i.e. we inherited the process from flutter then use uv.kill
?
Plenary shouldn't error just from using shutdown
since that's how I stop the flutter run process which doesn't error. I'm just wary of creating a job through plenary then potentially working around plenary using uv
to end that job especially since if we created it we should still have a reference to it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Job:shutdown
doesn't kill our devtools server. I've checked the devtools pid getting it from the json data and it's different from the job.pid
value so for some reason they are two different processes, that's why I'm killing it without plenary
.
This is what I get printing the job pid (third parameter in the handle_start function) and the devtools pid took from the json data
(using ui.notify({j.pid, devtools_pid})
Job:shutdown
errors because it passes nil
to our methods, we could just check if the argument data
is not nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I get using job:shutdown
First start the tools with the command:
And both processes are in the process tree (the parent of zsh
is my terminal)
Executing lua require('flutter-tools.dev_tools').stop() inside neovim shows the Devtools stopped message, but the processes are still there (both of them actually, same tree)
After exiting the processes, instead of terminating, are detached:
It doesn't matter if I run the .stop command myself or trigger it exiting neovim, the output is the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation @Charly6596 that's strange that there are different processes in which case I'm fine with you using uv.kill
and adding the necessary checks in the on_stderr
👍🏾
@akinsho That's a very good question
So it 2nd might not be the best solution, I've tried to provide support for both. We could do the 3rd option if we detect the full url (hence flutter started the service and we are running mobile), otherwise we start the process. |
6f0d4e6
to
d7dc66b
Compare
@Charly6596 I'd rather optimise for mobile since that is still by far the biggest segment of flutter users and make web best effort where it differs. So I guess from what you've said we can do 3 if it's mobile i.e. we have a full url so we just give dev tools the one flutter created and if we don't detect it then we start it? I think that should be configurable btw we shouldn't just start it without giving people a way out. Does that work? |
@akinsho yes, that sounds fine, I also agree it should be configurable |
@akinsho Alright, I've done a part of the 3rd option.
Just as a side note, my last commits could be squashed, I will keep them for now just in case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Charly6596 this LGTM thanks for your work on this, I've left one comment which I think is quite important to resolve around adding more conditions that could prevent running the app which I'd rather avoid
|
@Charly6596 lemme know if this ready to merge 👍🏾 think it was just the typo remaining |
@akinsho done 👍 |
@Charly6596 no we wouldn't using just message history you can find out more about it using Anyway, will merge this for now and can iterate later |
Added an autocmd triggered when vim is closed to kill the devtools process if it was started by the user.
As mentioned in #41, the flutter run command starts a dev tools server if running on mobile and has a parameter to start an already running dev tools server url, so I check if we are running it and pass the url if so.
The autocmd could be used to cleanup other modules if needed.
There is an issue, if we are not running devtools and we start the app, if we wanted to copy the url we would need to start another devtools process with the command, we would have 2 processes, one manage by flutter and another by our plugin
I think we have 3 options
flutter run
and pass the url as parameterdev_tools
module, preventing us from starting another server.I prefer the second one myself but I would like to know what you think.