Git Product home page Git Product logo

Comments (4)

dmitry-vychikov avatar dmitry-vychikov commented on August 12, 2024

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.

bweber avatar bweber commented on August 12, 2024

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.

dmitry-vychikov avatar dmitry-vychikov commented on August 12, 2024

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.

bweber avatar bweber commented on August 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.