Skip to content

Commit

Permalink
[ticket/14132] Use transaction for adding notifications to type table
Browse files Browse the repository at this point in the history
This will prevent a race condition that might occur by two posts being
submitted at the same time with the notification type IDs not being
cached.

PHPBB3-14132
  • Loading branch information
marc1706 committed Mar 8, 2016
1 parent f55a61d commit 10004c4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpBB/phpbb/notification/manager.php
Expand Up @@ -923,6 +923,8 @@ public function get_notification_type_id($notification_type_name)
{
$notification_type_ids = $this->cache->get('notification_type_ids');

$this->db->sql_transaction('begin');

if ($notification_type_ids === false)
{
$notification_type_ids = array();
Expand Down Expand Up @@ -957,6 +959,8 @@ public function get_notification_type_id($notification_type_name)
$this->cache->put('notification_type_ids', $notification_type_ids);
}

$this->db->sql_transaction('commit');

return $notification_type_ids[$notification_type_name];
}

Expand Down

3 comments on commit 10004c4

@vegettoGit
Copy link

@vegettoGit vegettoGit commented on 10004c4 May 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Mark,

I just upgraded my forum to 3.1.9 straight from 3.1.8.
Note that I am using mssql.

Since then, I have this problem every time a user posts a new message:

SQL ERROR [ mssqlnative ]

SQLSTATE: 42000 code: 3988 message: [Microsoft][SQL Server Native Client 11.0][SQL Server]Newtransaction is not allowed because there are other threads running in thesession. [3988]

I tracked it down to the function get_notification_type_id creating a new transaction, which seems to be related with this CL.
I have reverted this file to the 3.1.8 version for now, the previous version is working fine. Any ideas?

The callstack is:

FILE: [ROOT]/phpbb/notification/manager.php
CALL: phpbb\db\driver\factory->sql_transaction()

FILE: [ROOT]/phpbb/notification/type/base.php
CALL: phpbb\notification\manager->get_notification_type_id()

FILE: [ROOT]/phpbb/notification/manager.php
CALL: phpbb\notification\type\base->set_notification_manager()

FILE: [ROOT]/phpbb/notification/manager.php
CALL: phpbb\notification\manager->load_object()

FILE: [ROOT]/phpbb/notification/type/post.php
CALL: phpbb\notification\manager->get_item_type_class()

FILE: [ROOT]/phpbb/notification/manager.php
CALL: phpbb\notification\type\post->find_users_for_notification()

FILE: [ROOT]/phpbb/notification/manager.php
CALL: phpbb\notification\manager->add_notifications()

FILE: [ROOT]/includes/functions_posting.php
CALL: phpbb\notification\manager->add_notifications()

FILE: [ROOT]/posting.php
CALL: submit_post()

Thanks a lot,

@Nicofuma
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://support.microsoft.com/en-us/kb/3049257

Could you create a ticket please?

@vegettoGit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks,

The ticket has now been created: https://tracker.phpbb.com/browse/PHPBB3-14646

Cheers,

Please sign in to comment.