Skip to content
New issue

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

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

Already on GitHub? # to your account

[fix] Prevent exception when connection is closed #2967

Merged
merged 1 commit into from
May 22, 2024
Merged

[fix] Prevent exception when connection is closed #2967

merged 1 commit into from
May 22, 2024

Conversation

SanderMuller
Copy link
Contributor

@SanderMuller SanderMuller commented May 22, 2024

When the MongoDB connection disconnects, it currently unsets the connection property altogether. This causes the following exception when trying to use a MongoDB connection afterwards: Prevent Undefined property: MongoDB\Laravel\Connection::$connection

This PR sets the connection (client) to null instead of using unset().

Unfortunately there doesn't seem to be a reconnector configured by default, otherwise $connection->reconnect() could be used, but this has no effect right now. Could be a good next step for someone to implement.

It's possible that this issue only occurs when using Database Transactions (that's my use case. Didn't get any exceptions locally despite long periods of heavy load, but on our Atlas instance it is getting this exception a real lot)

Checklist

  • Add tests and ensure they pass
  • Add an entry to the CHANGELOG.md file
  • Update documentation for new features

@SanderMuller SanderMuller requested a review from a team as a code owner May 22, 2024 14:12
@SanderMuller SanderMuller requested a review from alcaeus May 22, 2024 14:12
@SanderMuller SanderMuller changed the title Patch 1 Prevent exception when connection is closed May 22, 2024
@SanderMuller SanderMuller changed the title Prevent exception when connection is closed [fix] Prevent exception when connection is closed May 22, 2024
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'll change the target branch to 4.3 and upmerge into 4.4.

@GromNaN GromNaN changed the base branch from 4.4 to 4.3 May 22, 2024 15:46
@GromNaN GromNaN enabled auto-merge (squash) May 22, 2024 15:48
@GromNaN
Copy link
Member

GromNaN commented May 22, 2024

Thank you @SanderMuller

@GromNaN GromNaN merged commit 6353520 into mongodb:4.3 May 22, 2024
25 checks passed
@GromNaN GromNaN added this to the 4.3 milestone May 31, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants