hostagent: stop leaking inotify watchers and re-spawn the gRPC stream after guest-agent reconnect#4895
Open
mn-ram wants to merge 1 commit intolima-vm:masterfrom
Open
hostagent: stop leaking inotify watchers and re-spawn the gRPC stream after guest-agent reconnect#4895mn-ram wants to merge 1 commit intolima-vm:masterfrom
mn-ram wants to merge 1 commit intolima-vm:masterfrom
Conversation
… after guest-agent reconnect startInotify never called notify.Stop on the channel returned to the rjeczalik/notify watchers, so each writable mount permanently leaked an inotify_init FD and the library's internal reader goroutine. The PostInotify gRPC client-stream was likewise never finalized with CloseSend, leaving the guest-agent handler parked. Worse, startInotify was spawned exactly once and looped silently on inotifyClient.Send failures, so once the guest agent restarted the stream was dead but the goroutine kept "running" with no path to re-establish it. Host-side file changes silently stopped propagating into the guest until the next limactl stop && start. Add `defer notify.Stop` and `defer inotifyClient.CloseSend()`, return an error on Send failure, and wrap the spawn in a 10s reconnect loop that mirrors what watchGuestAgentEvents already does for the Events stream. Signed-off-by: mn-ram <235066282+mn-ram@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4894.
startInotifynever callednotify.Stop(so the rjeczalik/notify reader goroutine and the per-mountinotify_initFDs leak) and never calledinotifyClient.CloseSend()(so the guest-agent'sPostInotifyhandler stays parked). It was also spawned exactly once and only logged onSenderrors, so after the first guest-agent restart the inotify gRPC stream was dead but the goroutine kept "running" — host-side file changes silently stopped reaching the guest untillimactl stop && limactl start.This change:
defer notify.Stop(mountWatchCh)anddefer inotifyClient.CloseSend(),inotifyClient.Sendfailure (instead of warn-and-loop), andstartInotifyis launched against the new client whenever the stream dies — matching whatwatchGuestAgentEventsalready does for theEventsstream.Test plan
go build ./...go vet ./pkg/hostagent/...go test ./pkg/hostagent/...mountInotify: trueLima instance,toucha file on the host before/aftersystemctl restart lima-guestagentinside the guest — file changes continue to propagate after the fix; onmasterthey stop after the first restart.