Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-81246

Detect invalid resources before trying to close them in SQLServer driver

XMLWordPrintable

    • 6
    • Team Hedgehog 2024 Sprint 1.3

      The bug has existed since 2010. And it becomes more obvious with PHP 8.2+ and the new driver. We only see this error because only PHP 8.3 is running with the new driver.
      The affected areas are all of the pages, and plugins that use

      get_recordset_***()
      

      The reason is with the new database driver, closing the recordset also close the statement resources. In the code, we're calling sqlsrv_free_stmt() to free the statement resources without checking whether it's already closed or not. Calling sqlsrv_free_stmt() with a closed statement resources will throw an exception

      Original
      Discovered after we bumped the phpsqlsrv to sqlsrv-5.12.0 so we can use PHP 8.3 in our main MSSQL Behat runs.

      The following Behat build running that PHP version returned 122 failures, which have the same errors:

      Potentially a regression from MDL-77144, but it needs to be confirmed as this MDL was integrated to 4.3 last year.

      Some HTML tags were opened in the body of the page but not closed.

      Some HTML tags were opened in the body of the page but not closed.
              Open header/footer at:
              line 2683 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 1458 of /lib/outputrenderers.php: call to xhtml_container_stack->push()
              line 960 of /grade/lib.php: call to core_renderer->header()
              line 144 of /grade/report/user/index.php: call to print_grade_page_head()
              Close header/footer at:
              line 2711 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 1520 of /lib/outputrenderers.php: call to xhtml_container_stack->pop()
              line 213 of /grade/report/user/index.php: call to core_renderer->footer()
              Open box at:
              line 2683 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 3356 of /lib/outputrenderers.php: call to xhtml_container_stack->push()
              line 3344 of /lib/outputrenderers.php: call to core_renderer->box_start()
              line 3094 of /lib/outputrenderers.php: call to core_renderer->box()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
              Close box at:
              line 2711 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 3368 of /lib/outputrenderers.php: call to xhtml_container_stack->pop()
              line 3344 of /lib/outputrenderers.php: call to core_renderer->box_end()
              line 3094 of /lib/outputrenderers.php: call to core_renderer->box()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
              line 2727 of /lib/outputlib.php: call to debugging()
              line 1591 of /lib/outputrenderers.php: call to xhtml_container_stack->pop_all_but_last()
              line 1518 of /lib/outputrenderers.php: call to core_renderer->container_end_all()
              line 3120 of /lib/outputrenderers.php: call to core_renderer->footer()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
      

      There are no more open containers. This suggests there is a nesting problem.

              Open header/footer at:
              line 2683 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 1458 of /lib/outputrenderers.php: call to xhtml_container_stack->push()
              line 960 of /grade/lib.php: call to core_renderer->header()
              line 144 of /grade/report/user/index.php: call to print_grade_page_head()
              Close header/footer at:
              line 2711 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 1520 of /lib/outputrenderers.php: call to xhtml_container_stack->pop()
              line 213 of /grade/report/user/index.php: call to core_renderer->footer()
              Open box at:
              line 2683 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 3356 of /lib/outputrenderers.php: call to xhtml_container_stack->push()
              line 3344 of /lib/outputrenderers.php: call to core_renderer->box_start()
              line 3094 of /lib/outputrenderers.php: call to core_renderer->box()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
              Close box at:
              line 2711 of /lib/outputlib.php: call to xhtml_container_stack->log()
              line 3368 of /lib/outputrenderers.php: call to xhtml_container_stack->pop()
              line 3344 of /lib/outputrenderers.php: call to core_renderer->box_end()
              line 3094 of /lib/outputrenderers.php: call to core_renderer->box()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
              line 2698 of /lib/outputlib.php: call to debugging()
              line 1520 of /lib/outputrenderers.php: call to xhtml_container_stack->pop()
              line 3120 of /lib/outputrenderers.php: call to core_renderer->footer()
              line 455 of /lib/setuplib.php: call to core_renderer->fatal_error()
              line ? of unknownfile: call to default_exception_handler()
               (Exception)
      

      Failed build

            huongn@moodle.com Huong Nguyen
            lameze Simey Lameze
            Simey Lameze Simey Lameze
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            CiBoT CiBoT
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 7 hours, 7 minutes
                7h 7m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.