Skip to content

Error dialog causes process to hang #16849

Closed

Description

@dktapps

Description

php-src/main/main.c

Lines 2121 to 2122 in dd4fc9a

/* Disable the message box for assertions.*/
_CrtSetReportMode(_CRT_ASSERT, 0);

This doesn't appear to produce the desired effect in latest versions of PHP. Dialog asserts are still generated during tests.

From my brief research it doesn't appear that 0 is a valid input for this function.

The better approach would probably be to redirect the output to stderr, as is done here when PHP_WIN32_HEAP_DEBUG is set:

php-src/sapi/cli/php_cli.c

Lines 1181 to 1186 in dd4fc9a

_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);

However, setting PHP_WIN32_HEAP_DEBUG enables a bunch of other stuff that isn't necessarily wanted.

This bug is problematic because it causes tests on Windows CIs to get stuck when asserts are triggered in debug builds.

PHP Version

8.1, 8.2, 8.3

Operating System

Windows

Activity

  1. self-assigned this
    on Nov 18, 2024
  2. cmb69 commented on Nov 18, 2024

    @cmb69
    Member

    From my brief research it doesn't appear that 0 is a valid input for this function.

    Indeed, it is undocumented. If I pass e.g. 16 instead, I get:

    Expression: fMode == _CRTDBG_REPORT_MODE || (fMode & ~(_CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW)) == 0

    Now one might think this is an errenous assertion, but there seems to be special support; from what I can tell it works _CRTDBG_MODE_FILE and _CRTDBG_FILE_STDERR have been set. If I only set _CRTDBG_MODE_FILE, the output goes nowhere since the report file defaults to INVALID_HANDLE_VALUE.

    Dialog asserts are still generated during tests.

    Not really. The dialogs are about the inevitable error after an assertion failure where abort() will be called.

    I think it's probably best to choose a minimal solution as bug fix (i.e. add _CrtSetReportMode(_CRT_ERROR, 0);), and possibly be more fancy as new feature (the dialogs are nifty during testing if a post-mortem debugger is attached).

  3. cmb69 commented on Nov 18, 2024

    @cmb69
    Member

    However, setting PHP_WIN32_HEAP_DEBUG enables a bunch of other stuff that isn't necessarily wanted.

    Well, it's likely the best memory leak detector available for MSVC builds (might find a couple of other memory related issues, but ASan is far superior). Set USE_ZEND_ALLOC=0, USE_TRACKED_ALLOC=1 and PHP_WIN32_DEBUG_HEAP=1 to find leaks when running php.exe (not implemented for other SAPIs).

  4. changed the title [-]Windows VC++ Runtime assert dialogs are not actually disabled[/-] [+]Error dialog causes process to hang[/+] on Nov 18, 2024
  5. added a commit that references this issue on Nov 18, 2024
    6070923
  6. dktapps commented on Nov 18, 2024

    @dktapps
    ContributorAuthor

    Dialog asserts are still generated during tests.

    Not really. The dialogs are about the inevitable error after an assertion failure where abort() will be called.

    Ah, I hadn't realized there was a difference.

  7. added a commit that references this issue on Nov 25, 2024
    e75061b
  8. added 3 commits that reference this issue on Nov 25, 2024
    929d42d
    4c57105
    ba6c005
  9. dktapps commented on Jan 15, 2025

    @dktapps
    ContributorAuthor

    Just an FYI @cmb69 this fix seems to prevent catching assertion failures under Visual Studio Debugger. Might be worth gating these report mode changes behind !IsDebuggerPresent().

  10. cmb69 commented on Jan 16, 2025

    @cmb69
    Member

    Thanks for the update, @dktapps! I don't think this is caused by e75061b, but there is certainly room for improvement. I'll try to have a closer look, but wouldn't be sad if someone beats me to it – PRs welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions