Skip to content

MemoryStorage Missing ParametersSnapshot Property #49

@frankyjquintero

Description

@frankyjquintero

MemoryStorage Missing ParametersSnapshot Property in ApplyStateContext

Description

The Hangfire.MemoryStorage plugin does not correctly implement the ParametersSnapshot property in the ApplyStateContext. This causes exceptions when using state filters that depend on this property.

Details

When comparing with the official SQL Storage implementation, the following differences are observed:

Steps to Reproduce

Create a state filter that accesses ParametersSnapshot:

public class OrchestratorStateFilter : IApplyStateFilter
{
    public void OnStateApplied(
        ApplyStateContext context,
        IWriteOnlyTransaction tx)
    {
        var backgroundJob = context.BackgroundJob;
        if (!FilterHelper.IsOrchestratorNode(backgroundJob.Job))
            return;
        
        #region Metadata base
        if (backgroundJob.ParametersSnapshot is null)
        {
            throw new Exception("ParametersSnapshot empty");
        }
        // ... rest of code
        #endregion
    }
}

Result: Exception is thrown when using Memory Storage, while SQL Storage works correctly.

Expected Behavior

The ParametersSnapshot property should be implemented in ApplyStateContext consistently with the official SQL Storage implementation.

Impact

  • Custom state filters that depend on ParametersSnapshot fail
  • Incompatibility with Hangfire's standard interface
  • Code that works with SQL Storage does not work with Memory Storage

Related References

  • IApplyStateFilter interface: Official Hangfire documentation
  • SQL Server Storage implementation: Reference implementation

Environment

  • Hangfire.MemoryStorage
  • Hangfire

Official sql storage.

https://github.com/HangfireIO/Hangfire/blob/333bd8eb228402abcee3f261cf32412e844f32c0/src/Hangfire.SqlServer/SqlServerConnection.cs#L286

Vs

memory storage

alternative
Hangfire.InMemory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions