Skip to content

[lldb] fix fd leak during lldb testsuite #118093

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

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

dlav-sc
Copy link
Contributor

@dlav-sc dlav-sc commented Nov 29, 2024

During lldb testing dotest.py opens files to dump testcase results, but doesn't close them.

This patch makes neccessary changes to fix the file descriptors leak.

During lldb testing dotest.py opens files to dump testcase results, but
doesn't close them.

This patch makes neccessary changes to fix the file descriptors leak.
@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2024

@llvm/pr-subscribers-lldb

Author: None (dlav-sc)

Changes

During lldb testing dotest.py opens files to dump testcase results, but doesn't close them.

This patch makes neccessary changes to fix the file descriptors leak.


Full diff: https://github.com/llvm/llvm-project/pull/118093.diff

1 Files Affected:

  • (modified) lldb/packages/Python/lldbsuite/test/lldbtest.py (+10-9)
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 8884ef5933ada8..1338d16a9171e2 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -865,13 +865,9 @@ def setUp(self):
         session_file = self.getLogBasenameForCurrentTest() + ".log"
         self.log_files.append(session_file)
 
-        # Python 3 doesn't support unbuffered I/O in text mode.  Open buffered.
-        self.session = encoded_file.open(session_file, "utf-8", mode="w")
-
         # Optimistically set __errored__, __failed__, __expected__ to False
         # initially.  If the test errored/failed, the session info
-        # (self.session) is then dumped into a session specific file for
-        # diagnosis.
+        # is then dumped into a session specific file for diagnosis.
         self.__cleanup_errored__ = False
         self.__errored__ = False
         self.__failed__ = False
@@ -1235,20 +1231,25 @@ def dumpSessionInfo(self):
         else:
             prefix = "Success"
 
+        session_file = self.getLogBasenameForCurrentTest() + ".log"
+
+        # Python 3 doesn't support unbuffered I/O in text mode.  Open buffered.
+        session = encoded_file.open(session_file, "utf-8", mode="w")
+
         if not self.__unexpected__ and not self.__skipped__:
             for test, traceback in pairs:
                 if test is self:
-                    print(traceback, file=self.session)
+                    print(traceback, file=session)
 
         import datetime
 
         print(
             "Session info generated @",
             datetime.datetime.now().ctime(),
-            file=self.session,
+            file=session,
         )
-        self.session.close()
-        del self.session
+        session.close()
+        del session
 
         # process the log files
         if prefix != "Success" or lldbtest_config.log_success:

@DavidSpickett
Copy link
Collaborator

It leaks the fds if dumpSessionInfo is never called, do I understand correctly? If so please add that information to the PR description.

@dlav-sc
Copy link
Contributor Author

dlav-sc commented Nov 29, 2024

It leaks the fds if dumpSessionInfo is never called

Yeah, dumpSessionInfo closes the session log file, but looks like dumpSessionInfo isn't called anywhere. Honestly, I don't understand the necessity of the function in that case, maybe we can remove it.

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

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

Happy for it to be fixed here and removed in another PR if it's unused.

Saves us resurrecting a broken function if we do want it back in future.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

I'm fine either way. I probably wouldn't bother fixing it before removing it, but since you already have the PR, you might as well merge it to cover the situation David is describing.

@dlav-sc dlav-sc merged commit 9a34a4f into llvm:main Dec 2, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants