This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Calling asyncore.file_wrapper.close twice may close unrelated file descriptor
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Nir Soffer, vstinner
Priority: normal Keywords:

Created on 2017-07-20 23:23 by Nir Soffer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2789 merged nirs, 2017-07-20 23:31
PR 2898 merged nirs, 2017-07-26 18:31
PR 2899 closed nirs, 2017-07-26 18:33
PR 2900 merged nirs, 2017-07-26 18:43
Messages (5)
msg298753 - (view) Author: Nir Soffer (Nir Soffer) Date: 2017-07-20 23:23
Commit 4d4c69dc35154a9c21fed1b6b4088e741fbc6ae6 added protection for double close in file_wrapper.close, but the test did not consider that fact that file_wrapper is dupping the file descriptor, making the test ineffective.

>>> fd1, fd2 = os.pipe()
>>> f = asyncore.file_wrapper(fd1)
>>> os.close(f.fd)
>>> f.close()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.5/asyncore.py", line 621, in close
    os.close(self.fd)
OSError: [Errno 9] Bad file descriptor
>>> f.fd
4
>>> fd3, fd4 = os.pipe()
>>> fd3
4
>>> f.close()
>>> os.close(fd3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 9] Bad file descriptor

f.close() closed an unrelated file descriptor.
msg299020 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 21:18
New changeset c648a93ae342ac28d2abbb100161eae4f907d001 by Victor Stinner (Nir Soffer) in branch 'master':
bpo-30980: Fix double close in asyncore.file_wrapper (#2789)
https://github.com/python/cpython/commit/c648a93ae342ac28d2abbb100161eae4f907d001
msg299021 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-24 21:20
Thanks for your fix Nir Soffer!
msg299272 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-26 23:24
New changeset 29094cec7cddd561cac16ce93443ca72d740de4d by Victor Stinner (Nir Soffer) in branch '2.7':
bpo-30980: Fix double close in asyncore.file_wrapper (#2789) (#2900)
https://github.com/python/cpython/commit/29094cec7cddd561cac16ce93443ca72d740de4d
msg299273 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-07-26 23:27
New changeset 25de5baf3eaebddbf879aacf49c0f614f922dc42 by Victor Stinner (Nir Soffer) in branch '3.6':
bpo-30980: Fix double close in asyncore.file_wrapper (#2789) (#2898)
https://github.com/python/cpython/commit/25de5baf3eaebddbf879aacf49c0f614f922dc42
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75163
2017-07-26 23:27:36vstinnersetstatus: open -> closed
versions: - Python 3.5
type: behavior
components: + Library (Lib)
resolution: fixed
stage: resolved
2017-07-26 23:27:10vstinnersetmessages: + msg299273
2017-07-26 23:24:54vstinnersetmessages: + msg299272
2017-07-26 18:43:30nirssetpull_requests: + pull_request2952
2017-07-26 18:33:59nirssetpull_requests: + pull_request2951
2017-07-26 18:31:33nirssetpull_requests: + pull_request2950
2017-07-24 21:20:07vstinnersetmessages: + msg299021
2017-07-24 21:18:10vstinnersetmessages: + msg299020
2017-07-20 23:36:31vstinnersetversions: - Python 3.3, Python 3.4
2017-07-20 23:31:27nirssetpull_requests: + pull_request2839
2017-07-20 23:23:23Nir Soffercreate