You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When scheduling a Hangfire job to call _analytics.Track with a RawEvent delegate, RawEvent is found to be null, resulting in a NullReferenceException. This issue does not occur when _analytics.Track is called directly, without scheduling through Hangfire, suggesting a discrepancy in how RawEvent is instantiated or accessed within Hangfire's execution context.
To Reproduce
Steps to reproduce the behavior:
Schedule ScheduleIntegrationTrialExpiringTomorrow as a background job using Hangfire.
Within ScheduleIntegrationTrialExpiringTomorrow, attempt to use _analytics.Track with a delegate that modifies RawEvent.
publicclassHangfireService:IHangfireService{privatereadonlyAnalytics_analytics;// Constructor that injects an Analytics instancepublicHangfireService(Analyticsanalytics){_analytics=analytics;}// Method to schedule a Hangfire job that will run after a delaypublicvoidScheduleIntegrationTrialJob(){// Creating a DTO with integration details to pass to the scheduled jobvarintegrationDetail=newSegmentIntegrationDetailDto{CompanyIdentifier="Company123",IntegrationCustomName="Marketing Integration",IntegrationGuideUrl="https://company.com/guide",IntegrationMessage="Welcome to the integration",IntegrationName="HubSpot Integration",IntegrationType="CRM"};// Scheduling the job to run after 60 secondsBackgroundJob.Schedule<HangfireService>(
x =>this.ScheduleIntegrationTrialExpiringTomorrow(integrationDetail),TimeSpan.FromSeconds(60));}// Method called by Hangfire to track an integration trial expiring eventpublicvoidScheduleIntegrationTrialExpiringTomorrow(SegmentIntegrationDetailDtointegrationDetail){// First call to _analytics.Track without a RawEvent delegate - this works as expected_analytics.Track("integration_trial_expiring_tomorrow",integrationDetail);// Second call to _analytics.Track with a RawEvent delegate - this causes a NullReferenceException// when scheduled through Hangfire, as RawEvent is null. However, this same call works // without issues when executed directly (not through Hangfire)._analytics.Track("integration_trial_expiring_tomorrow",integrationDetail, RawEvent =>{RawEvent.UserId="123";// Attempting to set the UserId, but RawEvent is null in this contextreturnRawEvent;});}}
Expected behavior
When scheduled as a background job, the RawEvent parameter is null, causing a NullReferenceException. Calling _analytics.Track directly without scheduling works as expected, even with the RawEvent delegate.
The text was updated successfully, but these errors were encountered:
hey @RaviAajugiya, the first call works as expected because the enrichment closure/delegate is null (see this line). the second call passes a closure/delegate and that closure/delegate is invoked with the enrichment result from previous plugins (see this line). I'd suggest to check if you have any plugins that returns null after processing.
if you don't have any custom plugins, there are 2 cases you might receive null values in the closure/delegate:
you have a destination plugin but it's not enabled (see this line)
analytics is not ready (see this line). this happens when analytics failed to fetch settings from network, or there are events being tracked before analytics got settings
in either case, you should do null checks yourself to prevent NullReferenceException
Describe the bug
When scheduling a Hangfire job to call _analytics.Track with a RawEvent delegate, RawEvent is found to be null, resulting in a NullReferenceException. This issue does not occur when _analytics.Track is called directly, without scheduling through Hangfire, suggesting a discrepancy in how RawEvent is instantiated or accessed within Hangfire's execution context.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
When scheduled as a background job, the RawEvent parameter is null, causing a NullReferenceException. Calling _analytics.Track directly without scheduling works as expected, even with the RawEvent delegate.
The text was updated successfully, but these errors were encountered: