bcc icon indicating copy to clipboard operation
bcc copied to clipboard

How to detach uprobes with invalid `/proc/fs` binary path after process terminates?

Open benkilimnik opened this issue 2 years ago • 5 comments

Say we have a uprobe attached to a binary accessed via /proc/<program-pid>/root/normal/path/to/binary. When the program terminates, the pid gets cleaned up so that the /proc/fs filepath is no longer valid. To clean up the dangling FD, we need to call detach_uprobe, but this fails because check_binary_symbol can't read the file.

Is there a way to make the detach API work with proc/fs binary paths after the pid is deleted?

benkilimnik avatar Dec 14 '23 17:12 benkilimnik

Another way of phrasing this question: how do we detach uprobes for short-lived processes/containers? What is the expected way to manage the uprobe lifecycle on containerized (ephemeral) applications?

benkilimnik avatar Dec 21 '23 22:12 benkilimnik

Could a BCC maintainer please comment on this?

It would be neat to have BCC track the open probes so that the binary can be removed from the file system and the probe can still be detached. For example, BCC could return a probe descriptor which internally could map to the open FDs. When the user calls detach probe, internally BCC uses the probe descriptor to find the aforesaid FDs and then closes them.

etep avatar Jan 16 '24 23:01 etep

For uprobe, current bcc has a mapping 'ev_name -> fd'. When detaching happens, bcc will follow 'ev_name -> fd' mapping and find the 'fd' and do detaching. I need to double check whether 'fd' (created at 'attach'/perf_event_open point) is still valid or not for short-lived process. Do you have an example to show the issue?

yonghong-song avatar Jan 17 '24 06:01 yonghong-song

We will craft an example. Thank you!

etep avatar Jan 17 '24 17:01 etep

any update on this issue ?

aayush-ap avatar Jun 03 '25 11:06 aayush-ap