-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Simplify VNet setup #41653
Simplify VNet setup #41653
Conversation
4b54ab9
to
0cff6ea
Compare
ae150fb
to
96f32a2
Compare
i had a bunch of implementation suggestions but overall i do like this much better now |
247450b
to
42b0636
Compare
9e3ca78
to
1dc9fb2
Compare
673bb43
to
caa3821
Compare
Didn't add anything new today besides the tests, just rebasing on top of my custom branch off of |
@nklaassen After I rebased it on top of I think it's maybe because I'm signing off today, so I'll try to hunt it down tomorrow. |
But generally it'd be nice if I could get this PR through reviews by the end of tomorrow, then I'd have Thursday and Friday to get other dependent PRs through. |
This is the weirdest thing... I had the osascript shell command redirecting logs to a file for debugging, and when I removed that, the /etc/resolver cleanup broke. But I can't debug it without logs 😭 so I added back the log redirect to |
It will be needed in VNet to issue app certs.
1dc9fb2
to
fb0c745
Compare
caa3821
to
3bbcc2a
Compare
@nklaassen @zmb3 Are there any other outstanding issues that I should address? It'd be great if I could split this tomorrow and merge it into #41413 and #41415. |
This comment was marked as outdated.
This comment was marked as outdated.
no it seems good to me, a bit hard to review on top of #41413, i'll make sure to review after you merge it in there |
Squashed from #41653 (only lib/vnet and tool/tsh).
fb0c745
to
a042be1
Compare
Squashed from #41653 (only lib/vnet and tool/tsh).
* Split vnet.Run into vnet.Setup and vnet.Run lib/teleterm cannot reuse this function due to different semantics of contexts within an RPC vs a CLI command. It needs one function that has request-response semantics and another that blocks that can be run from a separate goroutine. * tsh vnet: Select on ctx.Done too when awaiting TUN device Without this extra select on ctx.Done, interrupting tsh vnet at that moment would return an error about using a closed socket. That's because when the context gets canceled, another goroutine closes the socket. Instead, we should wait for either the cancelation of the context or socket.AcceptUnix returning a value. To test this, run `tsh vnet`. When the osascript prompt is shown, go back to the terminal and Ctrl+C the command. The previous version would show an error about using closed connection whereas this exits cleanly. * Do not show context canceled errors to user The previous version would show "context canceled" after sending SIGINT to tsh vnet after the user entered the password in the prompt and the TUN device was set up. * Fix handling of admin subcommand exiting prematurely with no err If the socket file was removed, the admin subcommand stops. The previous version of VNet would continue running. This version correctly propagates the fact that the admin subcommand has quit prematurely with no error and shuts down vnet.Manager as well. * Correctly report admin subcommand quitting prematurely Because of the changes from a couple of commits ago related to ignoring context.Canceled errors, if the admin subcommand was killed or has crashed, VNet would stop with no error message. This commit fixes that and propagates the error from osascript. * Avoid race condition when ctx gets canceled on awaiting TUN device * Refactor detecting premature exit with no error * Simplify shared VNet setup code Squashed from #41653 (only lib/vnet and tool/tsh). * Rename taskErr to expectedErr * Remove special treatment of context.Canceled in tsh vnet * Turn socket closer into critical task
Squashed from #41653 (only lib/vnet and tool/tsh).
* Split vnet.Run into vnet.Setup and vnet.Run lib/teleterm cannot reuse this function due to different semantics of contexts within an RPC vs a CLI command. It needs one function that has request-response semantics and another that blocks that can be run from a separate goroutine. * tsh vnet: Select on ctx.Done too when awaiting TUN device Without this extra select on ctx.Done, interrupting tsh vnet at that moment would return an error about using a closed socket. That's because when the context gets canceled, another goroutine closes the socket. Instead, we should wait for either the cancelation of the context or socket.AcceptUnix returning a value. To test this, run `tsh vnet`. When the osascript prompt is shown, go back to the terminal and Ctrl+C the command. The previous version would show an error about using closed connection whereas this exits cleanly. * Do not show context canceled errors to user The previous version would show "context canceled" after sending SIGINT to tsh vnet after the user entered the password in the prompt and the TUN device was set up. * Fix handling of admin subcommand exiting prematurely with no err If the socket file was removed, the admin subcommand stops. The previous version of VNet would continue running. This version correctly propagates the fact that the admin subcommand has quit prematurely with no error and shuts down vnet.Manager as well. * Correctly report admin subcommand quitting prematurely Because of the changes from a couple of commits ago related to ignoring context.Canceled errors, if the admin subcommand was killed or has crashed, VNet would stop with no error message. This commit fixes that and propagates the error from osascript. * Avoid race condition when ctx gets canceled on awaiting TUN device * Refactor detecting premature exit with no error * Simplify shared VNet setup code Squashed from #41653 (only lib/vnet and tool/tsh). * Rename taskErr to expectedErr * Remove special treatment of context.Canceled in tsh vnet * Turn socket closer into critical task
After a conversation with Alan, I decided to try out a couple of improvements which could simplify what I've done in #41413.
In #41413,
vnet.Setup
andvnet.Run
serve mostly as a big bags of stray functions that are needed to start VNet that I wanted to share between tsh and Connect. The main problem the split intoSetup
andRun
was solving is that tsh can set up VNet and then start it while blocking the main thread, whereas Connect cannot do this. The RPC in Connect that sets up VNet needs to return after a successful setup and let the VNet manager and the admin subcommand run in the background.This PR:
errgroup
to get rid of all the shenanigans I was doing with contexts in Improve handling of various lifecycle erorrs in VNet #41413.cancel
.The setup code ends up being a little bit more elaborate, but I think it's easier to follow and doesn't raise as much red flags as the one I introduced in #41413 does.