Page 1 of 1

Max # of Connections Error!

Posted: 15 Oct 2018, 15:51
by mohal_04
Laravel: 5.6
Aimeos: 2018.07
PHP: 7.1.18

Hi,

Lately, we are facing following error when we run "php artisan aimeos:setup."
In DBAL.php line 114:

Maximum number of connections (3) for "db" exceeded
And there is no log entry related to this error. So, please advise!

It displays right after when console says:
Using schema from catalog.php
Checking table "mshop_catalog":
So, I thought that maybe there is some issue with catalog.php file in my extension but I don't see any issue with that and no one from our team has made changes in it recently.

Thanks!

Re: Max # of Connections Error!

Posted: 16 Oct 2018, 06:34
by aimeos
Did you extend from an existing manager and replace parts of the code? This error happens if you acquire() a connection but don't call the appropriate release().

Re: Max # of Connections Error!

Posted: 20 Oct 2018, 11:08
by mohal_04
aimeos wrote:Did you extend from an existing manager and replace parts of the code? This error happens if you acquire() a connection but don't call the appropriate release().
Hi,

Thank you very much for your guidance. You really helped me fix this issue. Actually, we had a custom Setup Task that was using deprecated method to get DBAL connection, i.e.

Code: Select all

$dbal = $this->getConnection( $rname )->getRawObject();
So, it was opening the connection but it was not closing it. So, like you said, there was no "release" called. So, I have changed "getConnection" method with "acquire" and then I also added "release" method at the end.

Code: Select all

	/**
	 * Creates all required tables from schema if they don't exist
	 *
	 * @param array $files Associative list of resource names as keys and file paths as values
	 * @param boolean $clean True to remove left over columns or indexes, false to keep them untouched
	 */
	protected function setupSchema( array $files, $clean = false )
	{
		foreach( $files as $rname => $relpath )
		{
			$this->msg( 'Using schema from ' . basename( $relpath ), 1 ); $this->status( '' );

			// "getConnection" method is deprecated.
			// $dbal = $this->getConnection( $rname )->getRawObject();
			// Using "acquire" method instead of "getConnection."
			$conn = $this->acquire();
			$dbal = $conn->getRawObject();

			if( !( $dbal instanceof \Doctrine\DBAL\Connection ) ) {
				throw new \Aimeos\MW\Setup\Exception( 'Not a DBAL connection' );
			}

			$dbalManager = $dbal->getSchemaManager();
			$platform = $dbal->getDatabasePlatform();
			$schema = $this->getSchema( $rname );


			foreach( $this->getSchemaObjects( 'table', $relpath ) as $name => $dbalschema )
			{
				$this->msg( sprintf( 'Checking table "%1$s": ', $name ), 2 );

				$table = $dbalManager->listTableDetails( $name );
				$tables = ( $table->getColumns() !== [] ? array( $table ) : [] );

				$tableSchema = new \Doctrine\DBAL\Schema\Schema( $tables );
				$schemaDiff = \Doctrine\DBAL\Schema\Comparator::compareSchemas( $tableSchema, $dbalschema );
				$stmts = $this->remove( $this->exclude( $schemaDiff, $relpath ), $clean )->toSaveSql( $platform );

				$this->executeList( $stmts, $rname );
				$this->status( 'done' );
			}

			if( $schema->supports( $schema::HAS_SEQUENCES ) )
			{
				$sequences = $dbalManager->listSequences();

				foreach( $this->getSchemaObjects( 'sequence', $relpath ) as $name => $dbalschema )
				{
					$this->msg( sprintf( 'Checking sequence "%1$s": ', $name ), 2 );

					$seqSchema = new \Doctrine\DBAL\Schema\Schema( [], $sequences );
					$schemaDiff = \Doctrine\DBAL\Schema\Comparator::compareSchemas( $seqSchema, $dbalschema );
					$stmts = $this->remove( $schemaDiff, $clean )->toSaveSql( $platform );

					$this->executeList( $stmts, $rname );
					$this->status( 'done' );
				}
			}
			// Release DBAL connection
			$this->release($conn);
		}
	}
So, once again thank you very much for your help!

But there is one thing that I need to point out. You guys are making big changes in minor revision updates. Since I have updated to Aimeos 2018.10.*, this is my third (3rd) time that I am dealing with either deprecated code or extra code. I like product updates but please keep them simple and backward compatible, especially if, release is not something major or at-least change update version to something significant, which block composer from updating packages.

Thanks!

Re: Max # of Connections Error!

Posted: 21 Oct 2018, 11:49
by aimeos
We've made no API breaking changes after 2018.04 till 2018.10, i.e. no interface and method definition changed during this time. Problems always occur if you do something that you shouldn't have done at any time like using the raw PDO connection method instead of the officially provided methods. There are a few other parts where things may need to be adapted between 2018.04 and 2018.10 LTS, but they are very rare and only special cases.

2018.10 LTS will get bugfixes only so you will be on the save side whatever you've done and you can stay with this version up to five years with extended LTS support. Between 2018.04 and 2018.10 LTS you have to expect one or two things if you customized Aimeos heavily and this will be the same between 2019.04 and 2019.10. For the next major release (2019.01) we do all real breaking changes now. Hope that helps :-)