-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
Additiona read or write connection opened on reconnect with DB::disconnect() #30957
Comments
I do wonder how your connections are set up. |
I followed the official documentation for read and write configurations. https://laravel.com/docs/6.x/database#read-and-write-connections So basically my connections are named like this
I also tried using |
I can verify the issue and opened a PR with a proposed fix in #30998 |
@bernardwiesner you're linking to the 4.2 docs btw. |
@driesvints |
Pr was merged |
Cool :) |
Description:
When using read and write connections, calling DB::disconnect() and then executing a select query opens a connection to both read and write DB instead of just read. The same happens other way around, if you execute a write query after DB::disconnect() it opens both write and read instead of only write.
DB::disconnect() sets both readPdo and pdo to null. In DatabaseManager.php reconnect() calls refreshPdoConnections() that unnecessarily opens both read and write connections to the DB.
Using DB::purge() instead solves the problem scrapping the connection and not using the reconnect() when executing a new query.
I could use purge instead but I wonder if there is any downside to it. Seems like disconnect() and reconnect() are opening an unnecessary connection. This causes problems since it can potentially stop both write and read DB in situations when there are too many connections.
Steps To Reproduce:
Set up both a read and write DB in your database.php
Without disconnect
show full processlist
on mysql returns 1 open connection on read and 0 on write for the app.With disconnect
show full processlist
on mysql returns 1 open connection on read and 1 on write for the app.The text was updated successfully, but these errors were encountered: