[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2021-03-27 Thread Eryk Sun
Change by Eryk Sun : -- versions: +Python 3.10 -Python 3.7 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2021-03-27 Thread Eryk Sun
Change by Eryk Sun : -- Removed message: https://bugs.python.org/msg359981 ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-02-06 Thread Jakub Stasiak
Change by Jakub Stasiak : -- nosy: +jstasiak ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-16 Thread Paul Ollis
Paul Ollis added the comment: > I thought that if this raises a (normal) exception, it always means that it > did not have overtaken the `fd`, i.e. never results in an unreferenced file > object which has taken ownership of `fd`. The current CPython implementation does not guard against this

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-15 Thread Albert Zeyer
Albert Zeyer added the comment: > I think it is worth pointing out that the semantics of > > f = ``open(fd, closefd=True)`` > > are broken (IMHO) because an exception can result in an unreferenced file > object that has taken over reponsibility for closing the fd, but it can > also fail

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-15 Thread rekcartgubnohtyp
Change by rekcartgubnohtyp : -- nosy: +rekcartgubnohtyp ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-15 Thread Paul Ollis
Paul Ollis added the comment: I think it is worth pointing out that the semantics of f = ``open(fd, closefd=True)`` are broken (IMHO) because an exception can result in an unreferenced file object that has taken over reponsibility for closing the fd, but it can also fail without

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-15 Thread Albert Zeyer
Albert Zeyer added the comment: If you anyway accept that KeyboardInterrupt can potentially leak, by just using `except Exception`, it would also be solved here. -- ___ Python tracker

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-15 Thread Robert Xiao
Robert Xiao added the comment: Could this be solvable if `closefd` were a writable attribute? Then we could do file = None try: file = io.open(fd, ..., closefd=False) file.closefd = True except: if file and not file.closefd: os.close(fd)

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-14 Thread Eryk Sun
Eryk Sun added the comment: > I afraid that removing a file while the file descriptor is open > may not work on Windows. Seems this case is not well tested. os.remove will succeed on a file that's opened with O_TEMPORARY, which shares delete access (i.e. FILE_SHARE_DELETE). With classic

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-14 Thread Albert Zeyer
Albert Zeyer added the comment: Why is `except BaseException` better than `except Exception` here? With `except Exception`, you will never run into the problem of possibly closing the fd twice. This is the main important thing which we want to fix here. This is more important than missing

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Problems: 1. In general, it is hard to avoid leaks because an exception like KeyboardInterrupt or MemoryError can be raised virtually anywhere, even before we save a file descriptor. We may rewrite the code so that it will use few simple bytecode

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Carl Harris
Change by Carl Harris : -- nosy: +hitbox ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Jörn Heissler
Change by Jörn Heissler : -- nosy: +joernheissler ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: This issue is more complex. I am working on it. -- ___ Python tracker ___ ___ Python-bugs-list

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Ned Batchelder
Change by Ned Batchelder : -- keywords: +patch pull_requests: +17389 stage: -> patch review pull_request: https://github.com/python/cpython/pull/17985 ___ Python tracker ___

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Ned Batchelder
Change by Ned Batchelder : -- nosy: +nedbat ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- assignee: -> serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Fabio Sangiovanni
Change by Fabio Sangiovanni : -- nosy: +sanjioh ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Albert Zeyer
Albert Zeyer added the comment: Instead of `except:` and `except BaseException:`, I think better use `except Exception:`. For further discussion and reference, also see the discussion here: https://news.ycombinator.com/item?id=22028581 -- nosy: +Albert.Zeyer

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Seth Troisi
Change by Seth Troisi : -- nosy: +Seth.Troisi ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-13 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +serhiy.storchaka versions: -Python 3.5, Python 3.6 ___ Python tracker ___ ___

[issue39318] NamedTemporaryFile could cause double-close on an fd if _TemporaryFileWrapper throws

2020-01-12 Thread Robert Xiao
New submission from Robert Xiao : tempfile.NamedTemporaryFile creates its wrapper like so: try: file = _io.open(fd, mode, buffering=buffering, newline=newline, encoding=encoding, errors=errors) return _TemporaryFileWrapper(file, name, delete)