Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Timeout while getting a connection from pool." Hangfire.Postgres

I'm new to Hangfire, so probably I'm messing up somewhere. I have the Hangfire configured like in: https://github.com/HangfireIO/Hangfire#installation

but instead of:

 config.UseSqlServerStorage("<connection string or its name>");

I have:

 config.UsePostgreSqlStorage("Server=127.0.0.1;Port=5432;User Id=postgres;Password=pwd;Database=Hangfire");

So I created an Hangfire Database in my DB.

And then, I'm building and running my project. It is ok. Creating all tables in Hangfire DB at my postgres. It is working great.

But then, when I'm trying:

   BackgroundJob.Enqueue(() => HubService.SendPushNotificationToUsers(threadParticipants,  messageApi.SenderId, messageApi.SenderName, messageApi.ThreadId, messageApi.Content));

I'm receiving an exception with the InnerMessage:

  "Timeout while getting a connection from pool." postgres

Am I missing something?

like image 340
Gabriel Bastos Avatar asked Oct 20 '22 18:10

Gabriel Bastos


1 Answers

Try to turn off Connection Pool via ConnectionString or String Builder.

Here is how we do it

        var sb = new NpgsqlConnectionStringBuilder(connectionString);
        sb.Pooling = false;
        app.UseHangfire(config =>
        {
            config.UseActivator(new WindsorJobActivator(container.Kernel));
            config.UsePostgreSqlStorage(sb.ToString(), new PostgreSqlStorageOptions() { UseNativeDatabaseTransactions = true });
            config.UseServer();
        });
like image 136
Sergey Mirvoda Avatar answered Oct 26 '22 23:10

Sergey Mirvoda