Issue 30121: Windows: subprocess debug assertion on failure to execute the process (original) (raw)

Created on 2017-04-20 22:43 by Segev Finer, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (12)

msg292002 - (view)

Author: Segev Finer (Segev Finer) *

Date: 2017-04-20 22:43

subprocess triggers a debug assertion in the CRT on failure to execute the process due to closing the pipe handles in the except clause using os.close rather than .Close() (os.close closes CRT file descriptors and not handles).

In addition to that once this is fixed there is also a double free/close since we need to set self._closed_child_pipe_fds = True once we closed the handles in _execute_child so they won't also be closed in init.

To reproduce, do this in a debug build of Python:

import subprocess
subprocess.Popen('exe_that_doesnt_exist.exe', stdout=subprocess.PIPE)

See: https://github.com/python/cpython/pull/1218#discussion_r112550959

msg300458 - (view)

Author: Terry J. Reedy (terry.reedy) * (Python committer)

Date: 2017-08-17 21:18

I determined in #31228 (also on Windows, closed as a duplicate) that a debug build, bad file, and subprocess.PIPE are all required. Has this been tried on non-Windows? I confirmed the crash on 3.6. I do not have a 2.7 repository build.

The two lines above constitute a unittest that currently fails on a Windows debug build. Even if there is no such buildbot, I think a test should be added that will fail on developer machines with such builds. It should be skipped on non-debug and perhaps non-Windows machines.

msg300460 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-08-17 22:13

See https://github.com/python/cpython/pull/1224 and http://bugs.python.org/issue30121

msg300495 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-08-18 13:18

New changeset 4d3851727fb82195e4995c6064b0b2d6cbc031c4 by Victor Stinner (Segev Finer) in branch 'master': bpo-30121: Fix debug assert in subprocess on Windows (#1224) https://github.com/python/cpython/commit/4d3851727fb82195e4995c6064b0b2d6cbc031c4

msg300654 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-08-21 21:51

New changeset 9a83f651f31b47b3f6c8b210f7807b26e8c373a5 by Victor Stinner in branch 'master': Add test_subprocess.test_nonexisting_with_pipes() (#3133) https://github.com/python/cpython/commit/9a83f651f31b47b3f6c8b210f7807b26e8c373a5

msg300655 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-08-21 22:15

New changeset e76cb435563cd14bb085942dfefbb469b8f40aa9 by Victor Stinner in branch '3.6': [3.6] bpo-30121: Fix debug assert in subprocess on Windows (#1224) (#3173) https://github.com/python/cpython/commit/e76cb435563cd14bb085942dfefbb469b8f40aa9

msg300658 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-08-21 22:24

Python 2.7 doesn't seem to be affected by this issue. Extract of Popen.init:

    try:
        self._execute_child(args, executable, preexec_fn, close_fds,
                            cwd, env, universal_newlines,
                            startupinfo, creationflags, shell, to_close,
                            p2cread, p2cwrite,
                            c2pread, c2pwrite,
                            errread, errwrite)
    except Exception:
        # Preserve original exception in case os.close raises.
        exc_type, exc_value, exc_trace = sys.exc_info()

        for fd in to_close:
            try:
                if mswindows:
                    fd.Close()
                else:
                    os.close(fd)
            except EnvironmentError:
                pass

On Windows, fd.Close() is always used.

msg308532 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2017-12-18 09:41

Oops, I merged the pull requests, but I forgot to close the issue.

msg309741 - (view)

Author: STINNER Victor (vstinner) * (Python committer)

Date: 2018-01-09 22:11

Oops, I merged the pull requests, but I forgot to close the issue.

Oops, I forgot to close the issue, again... Thanks Segev for closing it, finally :-)

msg312365 - (view)

Author: Zachary Ware (zach.ware) * (Python committer)

Date: 2018-02-19 20:02

New changeset 5537646bfacec463b450871dde31cb06c44a0556 by Zachary Ware in branch 'master': bpo-30121: Fix test_subprocess for Windows Debug builds (GH-5758) https://github.com/python/cpython/commit/5537646bfacec463b450871dde31cb06c44a0556

msg312371 - (view)

Author: miss-islington (miss-islington)

Date: 2018-02-19 20:49

New changeset ef0bb5c7b76a49a5f3c5b85b5f9112cfefe54328 by Miss Islington (bot) in branch '3.6': bpo-30121: Fix test_subprocess for Windows Debug builds (GH-5758) https://github.com/python/cpython/commit/ef0bb5c7b76a49a5f3c5b85b5f9112cfefe54328

msg312373 - (view)

Author: miss-islington (miss-islington)

Date: 2018-02-19 21:00

New changeset 622a824802771fc5aa133ae92101bc8303360294 by Miss Islington (bot) in branch '3.7': bpo-30121: Fix test_subprocess for Windows Debug builds (GH-5758) https://github.com/python/cpython/commit/622a824802771fc5aa133ae92101bc8303360294

History

Date

User

Action

Args

2022-04-11 14:58:45

admin

set

github: 74307

2018-02-20 00:34:13

steve.dower

link

issue32764 superseder

2018-02-19 21:00:24

miss-islington

set

messages: +

2018-02-19 20:49:49

miss-islington

set

nosy: + miss-islington
messages: +

2018-02-19 20:04:14

miss-islington

set

pull_requests: + <pull%5Frequest5538>

2018-02-19 20:02:59

miss-islington

set

pull_requests: + <pull%5Frequest5537>

2018-02-19 20:02:41

zach.ware

set

messages: +

2018-02-19 19:49:35

zach.ware

set

pull_requests: + <pull%5Frequest5536>

2018-01-09 22:11:58

vstinner

set

messages: +

2018-01-09 21:35:27

Segev Finer

set

status: open -> closed
resolution: fixed
stage: patch review -> resolved

2017-12-18 09:41:35

vstinner

set

messages: +

2017-08-21 22:24:54

vstinner

set

messages: +

2017-08-21 22:15:26

vstinner

set

messages: +

2017-08-21 21:53:13

vstinner

set

pull_requests: + <pull%5Frequest3209>

2017-08-21 21:51:33

vstinner

set

messages: +

2017-08-18 13:27:56

vstinner

set

pull_requests: + <pull%5Frequest3167>

2017-08-18 13🔞17

vstinner

set

messages: +

2017-08-17 22:13:12

vstinner

set

messages: +

2017-08-17 21🔞32

terry.reedy

set

versions: + Python 3.6
nosy: + terry.reedy

messages: +

type: behavior -> crash
stage: patch review

2017-08-17 18:52:45

eryksun

link

issue31228 superseder

2017-04-21 16:29:11

vstinner

set

nosy: + vstinner

2017-04-20 23:22:46

Segev Finer

set

pull_requests: + <pull%5Frequest1346>

2017-04-20 22:43:55

Segev Finer

create