Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Borrow function of Connectoin Pool class requires a fix #16

Open
fakharksa opened this issue Sep 21, 2022 · 1 comment
Open

Borrow function of Connectoin Pool class requires a fix #16

fakharksa opened this issue Sep 21, 2022 · 1 comment

Comments

@fakharksa
Copy link

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);
@fakharksa
Copy link
Author

Ahh so you push the connection to the channel in return() function such that if the channel is full then it means that the channel is not able to accomodate more connections therefore you remove the connection from within the same return() function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant