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

Fix file descriptor leak, clobbered route updates #652

Merged
merged 3 commits into from
May 24, 2023

Conversation

tomc797
Copy link
Contributor

@tomc797 tomc797 commented May 7, 2023

These PR addresses a set of issues I discovered with Linux's process_routes_updates:

  1. The file descriptor for /tmp/ziti-tunnel-routes.XXXXXX is not closed, leading to a descriptor leak (lsof attached),
  2. When iterating the routes scheduled for deleted, the uv_fs_write was invoked with offset=0, meaning that the prior deletes were clobbered by the write,
  3. uv_fs_write was never checked for success, which could lead to corrupted route updates.

    ziti-edge-tunnel.lsof.txt

Signed-off-by: Tom Carroll <[email protected]>
Fixes an issue where all the writes occurred at the beginning of the
file.

Signed-off-by: Tom Carroll <[email protected]>
If write reports an error or short count, do not execute the route
update command.

Signed-off-by: Tom Carroll <[email protected]>
@tomc797 tomc797 requested a review from a team as a code owner May 7, 2023 03:23
uv_fs_req_cleanup(&unlink_req);
uv_fs_req_cleanup(&tmp_req);

Copy link
Member

Choose a reason for hiding this comment

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

probably better to close the file before blowing it off the file system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unlink just reduces the link count. The file is only removed from the filesystem when the reference count drops to zero. IMHO, the unlink-before-close is more axiomatic. If a funlink syscall is defined (FreeBSD has the funlinkat; been discussions on the Linux list at various times), you'll need the file descriptor to unlink the file.

@scareything scareything merged commit f5ce97e into openziti:main May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants