Ticket #4881: close-devnull-after-checking-patch.txt

File close-devnull-after-checking-patch.txt, 1.4 KB (added by lewq, 4 years ago)

Attaching a patch which forces the explicit closing of the file pointer to /dev/null in _checkDevFDSanity in case that's hanging around and polluting the list of file descriptors somehow (although it shouldn't cause three extra FDs).

Line 
1Index: twisted/internet/test/test_process.py
2===================================================================
3--- twisted/internet/test/test_process.py       (revision 31396)
4+++ twisted/internet/test/test_process.py       (working copy)
5@@ -599,6 +599,15 @@
6 
7 
8 
9+class FakeFile(object):
10+    """
11+    A fake file object which pretends it can be closed.
12+    """
13+    def close(self):
14+        pass
15+
16+
17+
18 class FakeResourceModule(object):
19     """
20     Fake version of L{resource} which hard-codes a particular rlimit for maximum
21@@ -682,8 +691,14 @@
22         """
23         This is a mock for L{open}.  It just keeps track of the fact that a file
24         has opened so an extra file descriptor is found in /dev/fd.
25+
26+        It also returns a L{FakeFile} which can be "closed". It would be more
27+        realistic to make the FD list shrink when the file is "fake closed" but
28+        it's not necessary for the detection algorithm we currently have in
29+        process.py.
30         """
31         self.openedFile = True
32+        return FakeFile()
33 
34 
35     def saveResourceModule(self):
36Index: twisted/internet/process.py
37===================================================================
38--- twisted/internet/process.py (revision 31396)
39+++ twisted/internet/process.py (working copy)
40@@ -530,6 +530,7 @@
41         start = self.listdir("/dev/fd")
42         fp = self.openfile("/dev/null", "r")
43         end = self.listdir("/dev/fd")
44+        fp.close()
45         return start != end
46 
47