On Thursday, October 24, 2019 at 10:30:40 PM UTC-7, Eugene Lai wrote:
>
> I have an API server running sinatra/thin/sequel connected to a managed 
> Postgres database provided by Azure Database for PostgreSQL.
>
> For background to my problem I refer to this: 
> https://docs.microsoft.com/en-us/azure/postgresql/concepts-connectivity
>
> I need to deal with this case of what Azure terms a transient error where 
> "...a connection to the database server being dropped. Also new connections 
> to a server can't be opened." for up to 60 seconds. Currently this means 
> our application will raise Sequel::DatabaseDisconnectError for every single 
> request for the duration of this outage.
>
> Microsoft recommends I implement a retry mechanism as such:
>
> Wait for 5 seconds before your first retry.
>> For each following retry, the increase the wait exponentially, up to 60 
>> seconds.
>> Set a max number of retries at which point your application considers the 
>> operation failed.
>
>
> I am thinking I should try to implement this at the point where a 
> connection is being checked out from the connection pool. At present I am 
> using connection_validator extension with timeout set to 15 minutes which 
> has solved the idle disconnect issue. Should I then set it at -1 instead 
> and then try to patch 
> Sequel::ConnectionValidator#acquire with this retry pattern?
>
> Is this the right way to go about it?
>

This appears to be a process-wide issue in Azure and not related to a 
specific connection, so you may want to set a global variable to a future 
timestamp if you get such an error, and then when checking out a 
connection, if the global variable is set and still in the future, don't 
try checking out a connection and instead just raise an error.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/fa59c5f8-1558-4829-a7fb-3f3ae75019c8%40googlegroups.com.

Reply via email to