Make Control safe to stop and wait on from any lifecycle state - #1794
Merged
Conversation
wadey
previously approved these changes
Jul 10, 2026
jrwren
previously approved these changes
Jul 10, 2026
jrwren
left a comment
Contributor
There was a problem hiding this comment.
LGTM. One thought, take it or leave it.
| } | ||
|
|
||
| p.control.Stop() | ||
| _ = p.control.Wait() |
Contributor
There was a problem hiding this comment.
Should the error from Wait be returned here?
If not, maybe include a comment as to why not?
Collaborator
Author
There was a problem hiding this comment.
Added a comment. Basically this is kardianos api forcing our hand (Stop returns an error) but we want to know if nebula exits without having called Stop and that thing wants to log an error. If we log from both the catch-all and Stop then we get 2 log statements. Doing it this way lets us avoid knowing if we called Stop vs nebula fatal'd to change where the log output happens.
JackDoan
approved these changes
Jul 10, 2026
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.
This branch makes nebula's
Controlsafe to drive as an embedded library through its whole lifecycle.Stopis now callable from any state (a never-startedControlreleases everythingMainacquired and poisons itself soStartreturnsErrAlreadyStopped), a newControl.Waitblocks until nebula has fully stopped and returns the first fatal reader error,Interface.Closeis idempotent, and failed activation orMainerrors now release the udp sockets and tun fd instead of leaking them.RebindUDPServeris gated on run state so a network-change handler racing shutdown can't touch a closed socket, and the iOS tun fd is set non-blocking so shutdown can't hang.