Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to close the file description when a method return it ? #95

Open
writePerfectCode opened this issue May 28, 2024 · 8 comments
Open

Comments

@writePerfectCode
Copy link

If a method of a service return a file description to the caller, where and how to close the file description ?
I have a try to close it in caller, it will a coredump in caller.
If have to close it in service, how ?

@williamspatrick
Copy link
Member

It should be closed by the recipient of the file descriptor (the caller?). I believe there are examples of using the file descriptor calls in bmcweb. Do you have examples of failing code?

@writePerfectCode
Copy link
Author

checked bmcweb, seems it just send file description as method param, but not a return value

@williamspatrick
Copy link
Member

https://github.com/openbmc/bmcweb/blob/de0c960c4262169ea92a4b852dd5ebbe3810bf00/redfish-core/lib/log_services.hpp#L863
https://github.com/openbmc/bmcweb/blob/de0c960c4262169ea92a4b852dd5ebbe3810bf00/redfish-core/lib/log_services.hpp#L808

I'm not sure how it works, but in this code it seems like the unix_fd is either leaked or somehow released automatically by the sd-bus infrastructure. I'd need to investigate more. There isn't any close call though.

@spinler
Copy link
Contributor

spinler commented May 29, 2024

When I did some code for a method that returned an FD with the sdbusplus bindings a few years ago, I think I remember that the FDs would leak if you didn't do anything, so I put in a sd_io_event_add_defer to close the file descriptor when the code got back to the event loop and that worked.

@williamspatrick
Copy link
Member

@spinler Any idea why you couldn't close it at the consumption location?

@spinler
Copy link
Contributor

spinler commented May 29, 2024

In the client? That's a dup'ed descriptor so the original in the server remained open.

@williamspatrick
Copy link
Member

For the server, I would expect:

  • FD is open.
  • FD is sent as part of the response.
  • FD can be immediately closed.

For the client, I would expect:

  • FD is open (due to it coming from the sendfd).
  • FD can be closed at any point and must be closed before the incoming message is released.

I don't really understand why the dup was ever necessary.

@writePerfectCode
Copy link
Author

I find a funny thing, I open a file, and set the fd as param to call a service method, while the servie handle the method call, I can see a new fd in /proc/xxx/fd for the service, after the method return, the caller close the fd, then I find the fd in for service /proc/xxx/fd also disapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants