Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions pkg/containerwatcher/v2/container_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/kubescape/node-agent/pkg/rulebindingmanager"
"github.com/kubescape/node-agent/pkg/rulemanager"
"github.com/kubescape/node-agent/pkg/sbommanager"
"github.com/kubescape/node-agent/pkg/utils"
"github.com/kubescape/workerpool"
"github.com/panjf2000/ants/v2"
)
Expand Down Expand Up @@ -159,9 +158,7 @@ func CreateContainerWatcher(
workerPool, err := ants.NewPoolWithFunc(cfg.WorkerPoolSize, func(i interface{}) {
enrichedEvent := i.(*events.EnrichedEvent)
eventHandlerFactory.ProcessEvent(enrichedEvent)
if enrichedEvent.Event.GetEventType() != utils.SyscallEventType {
enrichedEvent.Event.Release() // at this time we should not need the event anymore
}
enrichedEvent.Event.Release() // at this time we should not need the event anymore
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.

are we sure we can drop the condition here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In callback:
Data: event.Datasource.DeepCopy(event.Data), // each sub-event owns its own copy
...
event.Release() // original released here, after all sub-events are created

Each sub-event now holds an independent deep copy. When the worker pool calls:
enrichedEvent.Event.Release()
...it's releasing that sub-event's own copy, not shared memory. No other sub-event is affected.

So yes, dropping the condition is correct and intentional. The condition was only there to paper over the
shared-pointer problem. Now that every sub-event owns its data, the worker pool can safely call Release()
uniformly for all event types.

What do you think?

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.

ah right

})
if err != nil {
return nil, fmt.Errorf("creating worker pool: %w", err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/containerwatcher/v2/tracers/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ func (st *SyscallTracer) callback(event *utils.DatasourceEvent) {
syscallsBuffer := event.GetSyscalls()
for _, syscall := range decodeSyscalls(syscallsBuffer) {
st.eventCallback(&utils.DatasourceEvent{
Data: event.Data, // WARNING we pass the original data here, not a DeepCopy
Data: event.Datasource.DeepCopy(event.Data),
Datasource: event.Datasource,
EventType: event.EventType,
Syscall: syscall,
}, containerID, processID)
}
// Release the original deep-copied data since each sub-event now has its own copy
event.Release()
}

func decodeSyscalls(syscallsBuffer []byte) []string {
Expand Down