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

Feature: Add a method that checks if database is connected or not #80

Open
2 tasks done
ZeyoYT opened this issue Nov 13, 2023 · 6 comments
Open
2 tasks done

Feature: Add a method that checks if database is connected or not #80

ZeyoYT opened this issue Nov 13, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@ZeyoYT
Copy link

ZeyoYT commented Nov 13, 2023

Is your feature request related to a problem?

if somehow the connection dropped, there is no way to check if the driver is still connected or not, and you wont notice it until the application throws a exception

Describe the solution

a easy solution would be to add a method called checkConnetion or something that refers to checking the connection, the method would be a boolean and would return true if database is connected else false

Alternative methods

Yes, for now i am using a alternative way to check if its connected or not

public boolean checkConnection() {
        try {
            driver.ping();
        } catch (Exception e) {
            return false;
        }

        return true;
    }

SurrealDB version

1.0.0

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ZeyoYT ZeyoYT added the triage label Nov 13, 2023
@phughk
Copy link
Contributor

phughk commented Nov 13, 2023

Thanks for opening!

Is there any reason why would you need to know that the connection is severed if you aren't using the client? Surely, you would only need that information once you tried using the client, like in the existing solution, no?

@ZeyoYT
Copy link
Author

ZeyoYT commented Nov 13, 2023

well i run a discord bot, and it uses surrealdb, well for some reason the database dropped the connection, its been happning for quite a while recently, and sometimes even the surrealdb it self crashes, with this connection check we can atleast either try to reconnect to database or notify the issue, and might aswell connect to a backup

as for the issue with connection dropping i have asked this in surrealdb's discord and the devs has replied to it, but still its being discussed there

@phughk phughk added enhancement New feature or request and removed triage labels Nov 13, 2023
@phughk
Copy link
Contributor

phughk commented Nov 13, 2023

Are you able to capture the logs for the database crashing? And open an issue in the surrealdb/surrealdb repo for it - the database certainly shouldn't be crashing.

RE the disconnects - tcp connections can drop at any point and the only way to determine that the connection is dropped is with a timeout on receiving data. So a is connected doesn't particularly work, unless we are relying on heartbeats. I am not sure if the driver currently supports heartbeats, but could definitely look into it. Either way, I don't think the helper function would be particularly useful - you can't really action the boolean. We should have event handling of a failed connection instead.

@Prasad0535
Copy link

public boolean checkConnection() {
try {
driver.ping();
} catch (Exception e) {
return false;
}

    return true;
}

@phughk
Copy link
Contributor

phughk commented Nov 15, 2023

The implementation would be slightly different. The protocol already supports pings (and we should add that to the driver). We would then use that liveness as the value.

We can certainly add this method, as I can see people wanting it even though it's not quite necessary. It would certainly help in determining if a client passed as an argument has been connected or not. So we can add this.

@ZeyoYT
Copy link
Author

ZeyoYT commented Nov 15, 2023

it would be great if you guys add one, thanks in advance

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

No branches or pull requests

3 participants