View Issue Details

IDProjectCategoryView StatusLast Update
0037450mantisbtemailpublic2026-10-16 06:03
ReporterPredator Assigned To 
PrioritynormalSeveritymajorReproducibilitysometimes
Status newResolutionopen 
PlatformApache 2.4.66 / PHP 8.5.4-FPMOSUbuntuOS Version26.04.1 LTS
Product Version2.28.4 
Summary0037450: Session lock during shutdown email delivery delays issue pages after updates
Description

After adding a note or updating an issue, the redirected issue page
intermittently takes 5–15 seconds to load.

email_shutdown_function() calls fastcgi_finish_request() and then
email_send_all() while retaining the PHP session lock. The browser
receives the response and follows the redirect, but the next request
using the same session blocks in session_start() until email
processing finishes.

PHP-FPM slowlog captured nine affected requests, all waiting in
session_start() at core/session_api.php:149.

Expected behavior: save and release the active session before
finishing the response and processing notification emails.

Steps To Reproduce
  1. Use PHP-FPM with file-based sessions, email notifications enabled,
    and email_send_using_cronjob=OFF.
  2. Add a note or update an issue that generates notifications.
  3. Follow the redirect using the same session.
  4. When email delivery takes several seconds, the redirected request
    waits in session_start() until email processing finishes.

For deterministic reproduction, we tested the extracted shutdown
function through PHP-FPM with a four-second email stub and two
requests sharing one session. The second request waited 3964 ms
in session_start(). No real emails were sent by this test.

Additional Information

Database: MariaDB 11.8.6. PHP sessions use the files handler.

We added the following inside the existing
if( $g_email_shutdown_processing ) block, immediately before
fastcgi_finish_request():

if( PHP_SESSION_ACTIVE === session_status() ) {
    session_write_close();
}

This reduced the isolated test's session_start() wait to 0.02 ms.
Session data preservation and skip/cron/force branches were also tested.

After applying the change locally, 44 successful issue-page requests
took at most 104 ms, with no new slowlog entries above two seconds.
Users reported that the freezes had stopped.

Could you review this change for inclusion upstream?

Possibly related: 0017460 and 0034828.

TagsNo tags attached.
Attached Files
session-unlock-2.28.4-2026-10-15.patch (409 bytes)   
--- a/core/email_api.php
+++ b/core/email_api.php
@@ -2273,6 +2273,10 @@
 	log_event( LOG_EMAIL_VERBOSE, $t_msg );
 
 	if( $g_email_shutdown_processing ) {
+		# Release the session before background email delivery (Mirror, 2026-10-15).
+		if( PHP_SESSION_ACTIVE === session_status() ) {
+			session_write_close();
+		}
 		if( function_exists( 'fastcgi_finish_request' ) ) {
 			fastcgi_finish_request();
 		}

Activities