On the self-hosted instance, I see these errors appear quite often. What it is? ``` 02 Aug 2023 18:...
r
On the self-hosted instance, I see these errors appear quite often. What it is?
Copy code
02 Aug 2023 18:30:18:397 +0000 | ERROR | pid: cbf1c137-e9a8-440c-899f-a3aa49318855 | [pool-1-thread-4] thread | io.supertokens.multitenancy.MultitenancyHelper.lambda$refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged$0(MultitenancyHelper.java:145) | Tenant(, public, public) | io.supertokens.pluginInterface.exceptions.StorageQueryException: org.postgresql.util.PSQLException: ERROR: prepared statement "S_5" already exists
And these:
Copy code
02 Aug 2023 18:29:28:160 +0000 | ERROR | pid: cbf1c137-e9a8-440c-899f-a3aa49318855 | [http-nio-0.0.0.0-3567-exec-6] thread | io.supertokens.webserver.WebserverAPI.service(WebserverAPI.java:445) | Tenant(, public, public) | jakarta.servlet.ServletException: io.supertokens.pluginInterface.exceptions.StorageQueryException: org.postgresql.util.PSQLException: ERROR: bind message supplies 3 parameters, but prepared statement "S_7" requires 0
Also, I'm using https://neon.tech and I can see that supertoken always makes calls to the database or so, and that my computes are up as supertoken seems to ping it or try to do some queries or so. My app is before the release, so there are no clients and there are no calls to the database at all (I can see that by logs). So it's not my app that keeps computes alive. Is there a way to disable such pinging of the database? At least for the dev instance of supertoken that would be quite useful to save some money here.
r
hey @rip21
Errors like
prepared statement "S_5" already exists
are something that we haven't really seen before, even on our managed service. Which version of postgresql are you using?
r
> I can see that supertoken always makes calls to the database or so By default, supertokens keeps 10 connections to the db alive, and you can change this vlaue from the config.yaml (or docker env). But also, keeping those connections alive doesn't involve querying the db. If you are seeing queries to the db, its probably the cronjobs that are running in the core that are making those queries. Is ther a way to see those queries?
r
Any way to let it sync every 10 minutes or so? πŸ™‚
15
r
unfortunately, not at the moment. We can add a config for it though.
@sattvikc can help investigate the issues with the prepared statements error.
r
It happnes when this is called
refreshTenantsInCoreBasedOnChangesInCoreConfigOrIfTenantListChanged
I think it's caused by this SyncSettings cronjob.
BTW I'm on the latest tag. So, it should be fresh.
r
Thanks. We will investigate
r
I'll also try to replicate it locally. Also if you guys need I can create a connection string to branch on my neon instance, so you can check it.
And so you can also connect to it.
And see if it's maybe neon to blame here (as all these serverless/edge dbs are a bunch of smart hacks you know)
Also, this way you'll be able to query EXACT copy of the data/schema I currently have (I don't have any users it's all tinkering at this point so no worries)
s
@rip21 hey, I tried using neon db. I didn't see such a thing happening on my setup.
r
we couldn't connect to the connection uri you DMed me either
@sattvikc will say why
s
oh yea, there was a permission issue with the user -
Tenant(, public, public) | What caused the crash: io.supertokens.pluginInterface.exceptions.DbInitException: org.postgresql.util.PSQLException: ERROR: must be owner of table passwordless_codes
from quick check on the internet, that error message relates to pgpool, which I guess neon might be using internally. might be a good idea to check with their support once
r
Yeah, I tried it myself, and it seems that somehow the first deployment was unlucky and it got into this weird state of constant retries and failures of some of the queries. Stopping the task completely, and letting it restart (without blue-green deployment, but full stop, and start again) fixed it. No errors in the logs. Although, making this CRON job interval that calls SyncCoreConfigWithDb, configurable, will be nice. I'm not entirely sure what it does, and why it should be called that often πŸ™‚ BTW, is it also possible, to disable logging of
/hello
request, which is considered the default healthcheck? It just bloats the console so much. I usually reenable logging of health check routes for services only in case something goes wrong and I need to be 100% sure healthcheck is being called, which is rarely needed TBH.
FYI. Will kill the branch and connection that I gave you guys. Thanks for debugging.
r
You can set different log levels
r
And the last question for today,
Copy code
Failed to validate connection org.postgresql.jdbc.PgConnection@5ba4e963 (This connection has been closed.). Possibly consider using a shorter maxLifetime value.
Anything I can do about it? I assume, making it so DB never sleeps will do the trick, but it defeats the purpose of serverless computes. These are warns BTW.
r
I think these can be ignored.
r
So far only annoyance I have is that DBs never fall asleep. But I'm unsure if they will fall asleep at all even if a job will be running every 10 minutes and not every minute, as JDBC and Hikari are probably doing some SELECT 1 when checking the connection or so making it stay alive. Quite annoying. Will consult with Neon about that and maybe drop you guys some ideas here on how to make it more compatible with serverless Postgres DBs. (Neon separates storage and computes, and since computes are more expensive than storage, sleeping computes when not in load is perfect as it makes some dev env or preview databse cost to be virtually around 10-20 cents a month. While production costs +- the same as permanently hosted DB (when the app is busy it almost never sleeps. Having supertokens always keeping it alive with all this pinging, makes that money saving feature useless basically)
r
I see. Fair enough. Im not sure if we can easily solve for this though. Some of the cronjobs are very important indeed.
But open to ideas.
r
Like, based on name SyncCoreConfigWithDb Is it really that often that config is getting changed?
r
Not really, but if you deploy multiple cores and the config changes, it is really important that the configs are synced quickly across the cores
r
Wondering if https://www.postgresql.org/docs/9.0/sql-notify.html cannot be used here to notify instances of changes. E.g. new instance starts - changes config The old instance gets the notification and updates immediately. Either way, if it's a dealbreaker for serverless DBs, I think that can be a special section in the docs, that will explain this nuance and what to do to disable this cron job and what are side effects and what to do in case the config change is actually expected.
Although these notifications require an open connection. So probably it's not going to work and the cron job is better. Redis to sync stuff is another option πŸ˜› But that complicates the setup obviously.
I mean if sync means from instance to DB and then from DB to instance memory, this essentially means that service is not stateless.
And if it's not stateless it makes sense to push the state out either to DB, or to something fast, which is usually Redis. Don't know TBH still, what's the purpose of this SyncCoreConfigWithDb to be cron job. It should run on start once at the start and that is it. If services are stateless, they should just use new config from DB and that is it.
r
oh yea, well, that's true. So it's not fully stateless. The configs are stored in memory after reading from the db, so we need to sync the memory with the db. However, as you said, config changes aren't frequent, so depending on your use case, it may not be an issue to make that cron run once an hour or even more infrequently. You can always fork the core and change that time value. We have instrs on building it from source.
it's statelss as long as config remains the same*
r
I'll consider that πŸ˜› Having source code is such a nice thing πŸ˜› But I'm sure, in the future ppl will come asking the same question or so.
r
Sounds good. We shall look at it when we have time and it’s more of an urgency.
r
So, in the end, I opt out of hosting for dev and prod for the time being. I'll use the "hosted" version only in local development and for e2e testing.
r
Fair enough. So will you be using self hosted?
r
Nah, your cloud. As it's the most cost efficent for us for now. But self hosted for local development.
Self-hosted will be at least 80$ monthly in AWS or/and Neon computes. As Neon computes are always alive, it makes Neon make 0 sense. Using the cloud makes it 0 for next year or so (I don't expect us to have 5000 MAU 2 years anyway) And also makes Neon cost like 10 cents a month before we launch. And even after that, I think it will be around 2-3$. So 80-100$ compared to 0.10-3$, kinda obvious choice πŸ˜„
84 Views