Refactor Load() and fixup BPF lifecycle #104
Open
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.
There are a few issues with our current implementation that makes working with eBPF programs a bit less straightforward.
defer <link>.Close
. This means that as soon as the function exits, we close the loaded BPF program. This makes sense, as, per the function documentation, “A link may continue past the lifetime of the process if Close is not called.” The problem though with this is that there are instances where we want to lifetime of the program to live past this function. Cases such as:bee
loader on a BPF program that doesn’t contain any maps--no-tty
mode, the program gets unloaded immediately (as the WatchMaps() function will exit immediately and therefore the defer call will be executed promptly)WatchMaps()
function lives within the lifecycle of theLoad
function call. These bits of functionality should be disparate, and be called separately – therefore allowing the lifecycle to be managed explicitly by the caller. This is the onus behind the greatermapwatcher
folder refactor. This package is still tied to the loader, but instead lives in a subdirectory – allowing it to be called separately based on the needs of the caller. You’ll find that this is beneficial when running in--no-tty
mode, in which case we no longer have to create a dummyNoopWatcher
just to call theLoad()
function. Instead we can call load and then just wait for the context of the program to be canceled.