8000 Borrow function of Connectoin Pool class requires a fix · Issue #16 · open-smf/connection-pool · GitHub
[go: up one dir, main page]

Skip to content

Borrow function of Connectoin Pool class requires a fix #16

@fakharksa

Description

@fakharksa

On Line number 119 of "ConnectionPool.php" that lives in path "connection-pool/src/"

You return a new connection without pushing it into empty channel as below:
return $this->createConnection();

How about pushing this the new connection into channel (Pool) first, and then pop the connection, like below;

               $connection = $this->createConnection();`
               $ret = $this->pool->push($connection, static::CHANNEL_TIMEOUT);
                if ($ret === false) {
                    $this->removeConnection($connection);
                }

.. instead of returning the connection right away ?

Recommended Code with its full context, as below:

        if ($this->pool->isEmpty()) {
            // Create more connections
            if ($this->connectionCount < $this->maxActive) {
                $connection = $this->createConnection();                `
// Lets push new connection to the channel as below, because channel is initialized and still have space as condition ($this->connectionCount < $this->maxActive) has evaluated to true
               $ret = $this->pool->push($connection, static::CHANNEL_TIMEOUT);               
                if ($ret === false) {
                    $this->removeConnection($connection);
                }
            }
        }
        
        $connection = $this->pool->pop($this->maxWaitTime);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0