Transaction manager is corrupted...

Hi, here with another issue more weird than before:

My code

//Doing values insertion try { $transactionManager = new Phalcon\Mvc\Model\Transaction\Manager();

    $transaction = $transactionManager->get();

    $user = Users::findFirst("uid='".$userId."'");

    if ($user == false) {
        echo '1,Invalid uid';
        return;
    }

    $ipAddress = explode(',', $app->request->getClientAddress(true));

    $user->status = 'active';

    if ($user->save() == false) {
        $messages = $user->getMessages();
        $errors = '';
        for ($i = 0; $i < count($messages); $i++) {
            $errors .= '['.$messages[$i].'] ';
        }
        $transaction->rollback('Unable to save model [user], error: '.$errors);
    }

    $transaction->commit();

    echo '0';

} catch(Phalcon\Mvc\Model\Transaction\Failed $e) {
    echo '1,Some error happened';
} catch (Exception $e) {
    echo '1,Some error happened';
}

here is the exception I'm getting

Line: 84, Code: 0, Message: The transaction manager is corrupted

And line 84 is related to: $transaction = $transactionManager->get();

Any clue about this? How can this happen?



8.6k

Any clue about this?

I updated my servers to 0.9.1 version, and I'm still having this issues some times.



83.4k

Could you catch the exception and post the full backtrace?

try {
 //...
} catch(Exception $e) {
    print_r($e->getTrace());
}


8.6k

Sure:

Line: 53 File: .../app/request/toolbars/uninstall.php Message: The transaction manager is corrupted Trace: #0 ../app/request/toolbars/uninstall.php(53): Phalcon\Mvc\Model\Transaction\Manager->get()

1 [internal function]: {closure}()

2 .../public_html/index.php(167): Phalcon\Mvc\Micro->handle()

3 {main}



83.4k

Could you use getTrace instead of getTraceAsString()?

try {
 //...
} catch(Exception $e) {
    print_r($e->getTrace());
}


8.6k

Here you have it:

Line: 90 File: .../app/request/toolbars/install.php Message: The transaction manager is corrupted Trace: Array ( [0] => Array ( [file] => .../app/request/toolbars/install.php [line] => 90 [function] => get [class] => Phalcon\Mvc\Model\Transaction\Manager [type] => -> [args] => Array ( )

    )

[1] => Array
    (
        [function] => {closure}
        [args] => Array
            (
            )

    )

[2] => Array
    (
        [file] => .../public_html/index.php
        [line] => 167
        [function] => handle
        [class] => Phalcon\Mvc\Micro
        [type] => ->
        [args] => Array
            (
            )

    )

)

Line change because are different request operations, on both I use the transaction manager.

I put [...] in the paths because they are related to prod servers.

Hope this give you a better clue :-/



8.6k

Any news about this issue?



83.4k

I wasn't able to reproduce your problem; I would appreciate if you can attach a script that always throws this so we can check the problem better.



8.6k

Thats the issue, same script don't throw the exception all the time, until now I have no clue what is triggering this. I hoped you guys have at least a clue when this kind of exception can happen.



8.6k

Phalcon\Mvc\Model\Transaction\Manager Object ( [dependencyInjector:protected] => Phalcon\DI\FactoryDefault Object ( [services:protected] => Array ( [router] => Phalcon\DI\Service Object ( [name:protected] => router [definition:protected] => Phalcon\Mvc\Router [shared:protected] => 1 [sharedInstance:protected] => )

                [dispatcher] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => dispatcher
                        [_definition:protected] => Phalcon\Mvc\Dispatcher
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [url] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => url
                        [_definition:protected] => Closure Object
                            (
                                [static] => Array
                                    (
                                    )

                            )

                        [_shared:protected] => 
                        [_sharedInstance:protected] => 
                    )

                [modelsManager] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => modelsManager
                        [_definition:protected] => Phalcon\Mvc\Model\Manager
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [modelsMetadata] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => modelsMetadata
                        [_definition:protected] => Closure Object
                            (
                            )

                        [_shared:protected] => 
                        [_sharedInstance:protected] => 
                    )

                [response] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => response
                        [_definition:protected] => Phalcon\Http\Response
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [request] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => request
                        [_definition:protected] => Phalcon\Http\Request
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [filter] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => filter
                        [_definition:protected] => Phalcon\Filter
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [escaper] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => escaper
                        [_definition:protected] => Phalcon\Escaper
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [security] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => security
                        [_definition:protected] => Phalcon\Security
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [annotations] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => annotations
                        [_definition:protected] => Phalcon\Annotations\Adapter\Memory
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [flash] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => flash
                        [_definition:protected] => Phalcon\Flash\Direct
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [flashSession] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => flashSession
                        [_definition:protected] => Phalcon\Flash\Session
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [session] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => session
                        [_definition:protected] => Phalcon\Session\Adapter\Files
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [sessionBag] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => sessionBag
                        [_definition:protected] => Phalcon\Session\Bag
                        [_shared:protected] => 
                        [_sharedInstance:protected] => 
                    )

                [eventsManager] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => eventsManager
                        [_definition:protected] => Phalcon\Events\Manager
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [transactionManager] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => eventsManager
                        [_definition:protected] => Phalcon\Mvc\Model\Transaction\Manager
                        [_shared:protected] => 1
                        [_sharedInstance:protected] => 
                    )

                [db] => Phalcon\DI\Service Object
                    (
                        [_name:protected] => db
                        [_definition:protected] => Closure Object
                            (
                                [static] => Array
                                    (
                                        [config] => Phalcon\Config Object
                                            (
                                                [database] => Phalcon\Config Object
                                                    (
                                                        [adapter] => Mysql
                                                        [host] => ...
                                                        [username] => ...
                                                        [password] => ...
                                                        [name] => ...
                                                        [charset] => utf8
                                                        [port] => 3306
                                                    )

                                                [application] => Phalcon\Config Object
                                                    (
                                                        [modelsDir] => .../config/../models/
                                                        [rootDir] => .../config/../
                                                        [appDir] => .../config/../app/
                                                        [baseUri] => 
                                                    )

                                                [models] => Phalcon\Config Object
                                                    (
                                                        [metadata] => Phalcon\Config Object
                                                            (
                                                                [adapter] => Memory
                                                            )

                                                    )

                                            )

                                    )

                            )

                        [_shared:protected] => 
                        [_sharedInstance:protected] => 
                    )

            )

        [_sharedInstances:protected] => Array
            (
                [db] => Phalcon\Db\Adapter\Pdo\Mysql Object
                    (
                        [_eventsManager:protected] => 
                        [_descriptor:protected] => Array
                            (
                                [host] => ...
                                [username] => ...
                                [password] => ...
                                [dbname] => ...
                                [port] => 3306
                            )

                        [_dialectType:protected] => mysql
                        [_type:protected] => mysql
                        [_dialect:protected] => Phalcon\Db\Dialect\Mysql Object
                            (
                                [_escapeChar:protected] => `
                            )

                        [_connectionId:protected] => 1
                        [_sqlStatement:protected] => 
                        [_sqlVariables:protected] => 
                        [_sqlBindTypes:protected] => 
                        [_pdo:protected] => PDO Object
                            (
                            )

                        [_affectedRows:protected] => 
                        [_transactionLevel:protected] => 1
                    )

            )

        [_freshInstance:protected] => 1
    )

[_initialized:protected] => 
[_rollbackPendent:protected] => 1
[_number:protected] => 1
[_service:protected] => db
[_transactions:protected] =>

)



83.4k

hey odiel, there is a password in the Phalcon\Config section, I removed the comment



8.6k

Thanks so much, I didn't realize that same value was in more than one place. I will updated the comment.



8.6k

Hi guys, I'm still hammering my head with this issue. I set up a new env in a local VM computer, with Ubuntu and apache2, this is what I got from phpinfo() "PHP Version 5.3.10-1ubuntu3.5" for more details, I'm using phalcon 0.9.1

This is a completed new product on what I'm working on, here is the code for an action.

<?php

namespace Modules\Project\Target;

class Create extends \Classes\General\BasicController
{

    public function post()
    {
        $this->filter->add('under', new \Filters\AlphaUnderscore());
        $this->filter->add('interval_choices', new \Filters\Choices(array('i', 'h', 'd', 'w', 'm')));

        $id = $this->filter->sanitize($this->request->getPost('id'), 'under');
        $projectId = $this->filter->sanitize($this->request->getPost('project_id'), 'under');

        $description = $this->request->getPost('description');

        $preBuild = $this->request->getPost('prebuild');
        $build = $this->request->getPost('build');
        $postBuild = $this->request->getPost('postbuild');

        if ($id == '') {
            $this->jsonError("<b>ID</b> can't be empty.", 'id');
            return;
        }

        if ($projectId == '') {
            $this->jsonError("Unable to find the project you are working on, please reload the page and start over.", 'error');
            return;
        }

        //checking if project exist
        $project = \Models\Project::findFirst(array(
            'conditions' => 'id = ?1',
            'bind' => array(1 => $projectId)
        ));

        if ($project == false) {
            $this->jsonError("Unable to find the project you are working on, please reload the page and start over.", 'error');
            return;
        }

        //loading needed settings
        $setting = \Models\GlobalSetting::findFirst(array(
            'conditions' => 'id = ?1',
            'bind' => array(1 => 'scripts_path')
        ));

        if ($setting == false) {
            $this->jsonError("Unable to find the folder to store the projects, please contact the development team.", 'error');
            return;
        }


        //Creating project folder structure
        $this->_createFolderStructure($setting->value, $projectId, $id);

        //todo: log the errors creating project folder structure.

        //Creating script (xml) files
        $this->_createBuildFile($setting->value.'/'.$projectId.'/'.$id.'/scripts/', 'build.xml', $build);
        $this->_createBuildFile($setting->value.'/'.$projectId.'/'.$id.'/scripts/', 'prebuild.xml', $preBuild);
        $this->_createBuildFile($setting->value.'/'.$projectId.'/'.$id.'/scripts/', 'postbuild.xml', $postBuild);

        //todo: log the errors creating build files.


        //checking if target exist
        $targetModel = \Models\Target::findFirst(array(
            'conditions' => 'id = ?1',
            'bind' => array(1 => $id)
        ));

        if ($targetModel != false) {
            $this->jsonError("Target ID already exist, please choose another one.", 'error');
            return;
        }

        $manager = new \Phalcon\Mvc\Model\Transaction\Manager();
        $manager->collectTransactions();
        var_dump($manager);
        $transaction = $manager->get();

        $targetModel = new \Models\Target();
        $targetModel->setTransaction($transaction);
        $targetModel->id = $id;
        $targetModel->description = $description;
        $targetModel->project_id = $projectId;
        $result = $targetModel->save();

        //TODO: collect the errors and log it

        if ($result == false) {
            $transaction->rollback("Unable to save the Target, please try again the operation.");
            unset($transaction, $manager);
            //$this->jsonError("Unable to save the Target, please try again the operation.", 'error');
            return;
        }


        //Checking for triggers
        $triggers = $this->request->getPost('triggers');

        if ($triggers == 'commits') {
            $svnUrl = $this->request->getPost('svn_url');
            $svnUsername = $this->request->getPost('svn_username');
            $svnPassword = $this->request->getPost('svn_password');

            //Checking SVN connection
            $svn = new \Classes\SourceControl\Svn();
            try {
                $svn->checkConnection($svnUrl, $svnUsername, $svnPassword);
            } catch (\Exception $e) {
                $this->jsonError($e->getMessage(), 'error');
                return;
            }

            //Checking if SVN connection is already defined
            $svnModel = \Models\Def\SourceControl\Svn::findFirst(array(
                'conditions' => 'url = ?1 AND username = ?2 ',
                'bind'   => array(1 => $svnUrl, 2 => $svnUsername)
            ));

            if ($svnModel == false) {
                $svnModel = new \Models\Def\SourceControl\Svn();
            }

            //Storing the SVN connection params only if is new or password was updated
            if ($svnModel->password != $svnPassword) {
                $svnModel->setTransaction($transaction);
                $svnModel->url = $svnUrl;
                $svnModel->username = $svnUsername;
                $svnModel->password = $svnPassword;
                $result = $svnModel->save();

                if ($result == false) {
                    $transaction->rollback("Unable to save the SVN definition, please try again the operation.");
                    unset($transaction, $manager);
                    return;
                }
            }

            //Trigger interval values
            $svnCheckEvery = $this->filter->sanitize($this->request->getPost('svn_check_every'), 'int');
            $svnCheckInterval = $this->filter->sanitize($this->request->getPost('svn_check_interval'), 'interval_choices');

            if ($svnCheckEvery == 0) {
                $svnCheckEvery = 5;
                $svnCheckInterval= 'i';
            }

            if ($svnCheckInterval == false) {
                $svnCheckInterval= 'i';
            }

            switch ($svnCheckInterval) {
                case 'i':   //Minutes
                    $svnCheckInterval = 'minutes';
                    break;
                case 'h':   //Hours
                    $svnCheckInterval = 'hours';
                    break;
                case 'd':   //Days
                    $svnCheckInterval = 'days';
                    break;
                case 'w':   //Weeks
                    $svnCheckInterval = 'week';
                    break;
                case 'm':   //Months
                    $svnCheckInterval = 'month';
                    break;
            }

            $triggerModel = new \Models\Target\Trigger();
            $triggerModel->setTransaction($transaction);
            $triggerModel->type = 'commits';
            $triggerModel->code = 'svn::id='.$svnModel->id;
            $triggerModel->execute_every = " + ".$svnCheckEvery." ".$svnCheckInterval;
            $triggerModel->next_execution = date('Y-m-d H:i:s', strtotime(" + ".$svnCheckEvery." ".$svnCheckInterval));
            $triggerModel->target_id = $id;
            $result = $triggerModel->save();

            if ($result == false) {
                $transaction->rollback("Unable to save create the trigger for the target, please try again.");
                unset($transaction, $manager);
                return;
            }
        }

        $transaction->commit();
        unset($transaction, $manager);

        $this->jsonOk();
    }


    private function _createFolderStructure($path, $projectId, $targetId)
    {
        if (is_dir($path.'/'.$projectId.'/'.$targetId.'/scripts/') == false) {
            if (@mkdir($path.'/'.$projectId.'/'.$targetId.'/scripts/', 0777, true) == false) {
                $this->jsonError("Unable to create the project folder structure, please contact the development team.", 'error');
                return;
            }
        }

        if (is_dir($path.'/'.$projectId.'/'.$targetId.'/builds/') == false) {
            if (@mkdir($path.'/'.$projectId.'/'.$targetId.'/builds/', 0777, true) == false) {
                $this->jsonError("Unable to create the project folder structure, please contact the development team.", 'error');
                return;
            }
        }

        if (is_dir($path.'/'.$projectId.'/'.$targetId.'/temp/source/') == false) {
            if (@mkdir($path.'/'.$projectId.'/'.$targetId.'/temp/source', 0777, true) == false) {
                $this->jsonError("Unable to create the project folder structure, please contact the development team.", 'error');
                return;
            }
        }
    }

    private function _createBuildFile($path, $file, $content)
    {
        if (is_dir($path) == false) {
            $this->jsonError("Unable to find the Script directory for the project, please contact the development team.", 'error');
            return;
        }

        $hdl = fopen($path.$file, 'w');
        if ($hdl == false) {
            $this->jsonError("Unable to create the '.$file.' file in the script directory, please contact the development team.", 'error');
            return;
        }

        fwrite($hdl, $content);
        fclose($hdl);
    }

}


8.6k

The issue, some times when I insert a new "Target" the values go to the DB without any problem, but in other occasions I get "Transaction manager is corrupted" exception, this is very randomly, and until now I haven't figure out the cause. As I said this is a local VM, there is not traffic rather than me accessing it.

Note: the root password is ok, you don't need to remove the object below because it.

Here is the $manager object dump.

http://pastebin.com/W5rW3ij3

And the exception:

object(Phalcon\Mvc\Model\Transaction\Exception)#41 (7) {
  ["message":protected]=>
  string(36) "The transaction manager is corrupted"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(67) "/home/www/dev.micro/site/site/app/modules/project/target/create.php"
  ["line":protected]=>
  int(83)
  ["trace":"Exception":private]=>
  array(4) {
    [0]=>
    array(6) {
      ["file"]=>
      string(67) "/home/www/dev.micro/site/site/app/modules/project/target/create.php"
      ["line"]=>
      int(83)
      ["function"]=>
      string(3) "get"
      ["class"]=>
      string(37) "Phalcon\Mvc\Model\Transaction\Manager"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(0) {
      }
    }
    [1]=>
    array(4) {
      ["function"]=>
      string(4) "post"
      ["class"]=>
      string(29) "Modules\Project\Target\Create"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(0) {
      }
    }
    [2]=>
    array(6) {
      ["file"]=>
      string(65) "/home/www/dev.micro/site/site/app/classes/General/Application.php"
      ["line"]=>
      int(102)
      ["function"]=>
      string(6) "handle"
      ["class"]=>
      string(17) "Phalcon\Mvc\Micro"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(0) {
      }
    }
    [3]=>
    array(6) {
      ["file"]=>
      string(51) "/home/www/dev.micro/site/site/public_html/index.php"
      ["line"]=>
      int(139)
      ["function"]=>
      string(5) "start"
      ["class"]=>
      string(27) "Classes\General\Application"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(0) {
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
}