Skip to content

Make Control safe to stop and wait on from any lifecycle state - #1794

Merged
nbrownus merged 3 commits into
masterfrom
embedder-lifecycle
Jul 10, 2026
Merged

Make Control safe to stop and wait on from any lifecycle state#1794
nbrownus merged 3 commits into
masterfrom
embedder-lifecycle

Conversation

@nbrownus

@nbrownus nbrownus commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

This branch makes nebula's Control safe to drive as an embedded library through its whole lifecycle. Stop is now callable from any state (a never-started Control releases everything Main acquired and poisons itself so Start returns ErrAlreadyStopped), a new Control.Wait blocks until nebula has fully stopped and returns the first fatal reader error, Interface.Close is idempotent, and failed activation or Main errors now release the udp sockets and tun fd instead of leaking them. RebindUDPServer is 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.

@nbrownus nbrownus added this to the v1.11.0 milestone Jul 9, 2026
wadey
wadey previously approved these changes Jul 10, 2026
jrwren
jrwren previously approved these changes Jul 10, 2026

@jrwren jrwren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. One thought, take it or leave it.

}

p.control.Stop()
_ = p.control.Wait()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the error from Wait be returned here?

If not, maybe include a comment as to why not?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@nbrownus
nbrownus dismissed stale reviews from jrwren and wadey via fced21d July 10, 2026 15:18
@nbrownus
nbrownus merged commit ab736e4 into master Jul 10, 2026
20 checks passed
@nbrownus
nbrownus deleted the embedder-lifecycle branch July 10, 2026 15:35
@nbrownus nbrownus mentioned this pull request Jul 23, 2026
56 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants