Comments (4)
Is there something wrong with your hangfire instance? Does this exception affect how the jobs are processed?
Does it happen if you use just a connection string without connection factory?
Please attach all code with hangfire configuration. Now it is not clear how you pass connection factory to hangfire.
Example using connection factory can be found here: #322 (comment)
from hangfire.postgresql.
We are using a managed identity with Google Cloud, so we are registering our NpgSqlDatasource
like this:
services.AddSingleton(BuildGoogleDataSource(configuration));
private static NpgsqlDataSource BuildGoogleDataSource(IConfiguration configuration)
{
var credentials = GoogleCredential.GetApplicationDefault();
var scopedCredentials = credentials.CreateScoped("https://www.googleapis.com/auth/sqlservice.login");
var dataSourceBuilder = new NpgsqlDataSourceBuilder();
dataSourceBuilder.UsePeriodicPasswordProvider((_, cancellationToken) =>
new ValueTask<string>(scopedCredentials.UnderlyingCredential
.GetAccessTokenForRequestAsync(cancellationToken: cancellationToken)),
TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(0));
dataSourceBuilder.ConnectionStringBuilder.ConnectionString = configuration.GetConnectionString("MyDatabase");
return dataSourceBuilder.Build();
}
Our Hangfire configuration is like this:
services.AddSingleton<IConnectionFactory, ConnectionFactory>();
services
.AddHangfire((sp, options) =>
{
options.UsePostgreSqlStorage(o => o.UseConnectionFactory(sp.GetRequiredService<IConnectionFactory>()),
new PostgreSqlStorageOptions { PrepareSchemaIfNecessary = false });
})
.AddHangfireServer(o => o.Queues = ["default"]);
The ConnectionFactory is in my original post.
Using the NpgSqlDatasource
is working perfectly in our Healthcheck and EntityFramework configuration. We are only seeing connection exceptions using this with Hangfire.
from hangfire.postgresql.
We are only seeing connection exceptions using this with Hangfire.
So what is the real problem you are trying to solve? Is hangfire not working for you? Also what severity level is your exception logged with? Is it error or warning?
This exception is coming from Distributed lock inside of recurring job scheduler. This might mean that you have 2 or more servers that try to perform scheduled operations, while only one manages to acquire the lock. This is not a bug – just normal operation.
Or else there has been some work in hangfire to enable parallel execution of recurring jobs even within one server. Potentially, this could lead to similar exceptions, but I don't have experience with that new feature yet.
from hangfire.postgresql.
The main problem we are running into is these are firing as unhandled exceptions and triggering alerts in our application monitoring services. We are seeing the same exception with other things like ServerHeartbeatProcess
as well.
It doesn't seem to be impacting Hangfire working as I see it handling background jobs and the dashboard works, but it seems to be some sort of connection timeout that isn't being gracefully handled, the subsequent usage of the connection throws an exception and then it tries to get a new connection, but since this is internal to Hangfire/Postgres library, my options there are limited to resolve it.
I could put some sort of filter in our logging config in our appsettings to downgrade this to a warning, but that may mask other issues in the future.
Thoughts?
from hangfire.postgresql.
Related Issues (20)
- How inject in hangfire postgres connection HOT 5
- NpgsqlConnectionStringBuilder is not giving updated builder instance for new connection string value. HOT 6
- Unable to run the solution as is in .NET 8 HOT 2
- ExpirationManager issue removing million of jobs HOT 13
- Performance Issues with Postgress HOT 29
- Job supposed to be re-queued on worker shutdown but it never is HOT 38
- NpgsqlDataSource support HOT 3
- How to migrate obsolete PostgreSqlBootstrapperConfigurationExtensions usage HOT 2
- Error "unsupported Unicode escape sequence" after update HOT 1
- EnableHeavyMigrations missing from PostgreSqlStorageOptions HOT 1
- One jobId with two entries of same parameter name in db HOT 1
- Not operating: "Could not place a lock on the resource 'hangfire:locks:schedulepoller': Lock timeout" HOT 1
- 1.8 migration guide HOT 1
- Could not place a lock on the resource 'hangfire:lock:recurring-job:jobid': Lock timeout. HOT 2
- Processing order in Hangfire.PostgreSql? HOT 2
- Job count by state query performance HOT 4
- Implement the List-returning GetFirstByLowestScoreFromSet HOT 3
- Attempting to retrieve FetchedJobs crashes due to duplicates
- Loading 5000 Failed jobs when there's even more causes a Memory Leak HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hangfire.postgresql.