News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Cron error

Started by Sir Osis of Liver, April 21, 2025, 10:04:27 PM

Previous topic - Next topic

Sir Osis of Liver

Just started seeing these -


Type of error
Cron

Error message
2: Undefined array key 812

File
/home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php
Line 1413

URL of page causing the error
https://www.new.tradgang.com/tgsmf21/index.phphttps://www.new.tradgang.com/tgsmf21/cron.php

Backtrace information

    #0: smf_error_handler_cron()
    Called from /home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php on line 1413
    #1: scheduled_paid_subscriptions()
    Called from /home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php on line 116
    #2: AutoTask()
    Called from /home/tradgang/public_html/tgsmf21/cron.php on line 150

When in Emor, do as the Snamors.
                              - D. Lister

Doug Heffernan

Quote from: Sir Osis of Liver on April 21, 2025, 10:04:27 PMJust started seeing these -

What was the last change/modification done to the forum prior to this happening?

Kindred

It looks like something added a scheduled task with potential missing data checks
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sir Osis of Liver

It's an old 2.0.19 forum that was running in php 5.5.  Migrated to new server, php 8.0, upgraded to 2.1.4, installed Ad Management, Global Headers & Footers, Automatic Attachment Rotation & Resize mods.  Running ok except for those two errors yesterday.  No tasks scheduled for that time.  Maybe something in the database?
When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

I'd check & re-save the notification preferences for that user (id=812). 
https://github.com/SimpleMachines/SMF/blob/19a9de63d8b895c6f931137bba09c3d5a79caf52/Sources/ScheduledTasks.php#L1413

First guess is that the notification preferences got out of sync somehow, either due to an upgrader issue or user deletion, or ill-timed preference changes, etc., etc. 
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

User id=812 was last active Jan 2025, forum was in 2.0.19, so would there be any notification preferences?
When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

Been a while...  IIRC, it was all about email notifications in 2.0.  I believe email requests convert to alert requests upon migration.

A question worth asking is born in experience & driven by necessity. - Fripp

Illori

Quote from: Sir Osis of Liver on April 21, 2025, 10:04:27 PM
#1: scheduled_paid_subscriptions()
Called from /home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php on line 116

does this part of the backtrace mean it has something to do with a paid sub for this user?

Sir Osis of Liver

Yes, the user has a paid subscription from 2.0.19 that expires in May.  Couple more scheduled task errors today -


Type of error
Undefined_vars

Error message
2: Undefined array key 16384
File
/home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php
Line 1413
URL of page causing the error
https://www.new.tradgang.com/tgsmf21/index.php?action=printpage;topic=129318.0;images

Backtrace information

    #0: smf_error_handler()
    Called from /home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php on line 1413
    #1: scheduled_paid_subscriptions()
    Called from /home/tradgang/public_html/tgsmf21/Sources/ScheduledTasks.php on line 116
    #2: AutoTask()
    Called from /home/tradgang/public_html/tgsmf21/Sources/Load.php on line 2659
    #3: loadTheme()
    Called from /home/tradgang/public_html/tgsmf21/index.php on line 229
    #4: smf_main()
    Called from /home/tradgang/public_html/tgsmf21/index.php on line 186


Timestamp is same as Paid Subscription Checks run time.


When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

Did you try the recommendation made above?

Quote from: shawnb61 on April 22, 2025, 05:37:49 PMI'd check & re-save the notification preferences for that user (id=812). 

It's hard working with you when you usually ignore input.  In all honesty, why would anyone bother?
 
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

Yes, I did that.  The errors it posted after that are different.
When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

#11
What was shared above is the same error, exact same line of code, just for a different user.

First guess is the upgrader was not able to complete the alert prefs updates for some reason.  Now any attempt to send a notification fails due to missing prefs.

2.0 notification settings were all over the place - members, themes.  The upgrader moved them to the user_alerts_prefs table.

I would check the completeness of the user_alerts_prefs table.  Are there entries for user 16384?

All users?

If many are missing, you may need to figure out how to rerun the upgrader (assuming the source data is still present)...   Or at least store defaults for users who are missing settings.
A question worth asking is born in experience & driven by necessity. - Fripp

shawnb61

#12
Specific questions to help figure out how big the problem is, & how best to fix...

1.  How many members?
   Query:  SELECT COUNT(DISTINCT id_member) FROM smf_members;

2.  How many members have alert preferences?
   Query:  SELECT COUNT(DISTINCT id_member) FROM smf_user_alerts_prefs;

The above 2 values may not match exactly, but they should be close...  (Deleted users, unapproved users, etc., can cause these 2 values to stray...)

3.  Is the source data still available on smf_members, i.e., do these 4 fields still exist on the members table?
   notify_regularity, notify_send_body, notify_types, notify_announcements

4.  Is the source data still available on smf_themes?
   Query:  SELECT COUNT(DISTINCT id_member) FROM smf_themes WHERE variable = 'auto_notify';
   
In theory, I believe these should be 0.  If it is close to your user count, then this upgrade step did not properly complete.  If you want to try to recapture this data, e.g., due to a failed upgrade, it would be helpful to still have this around, though...

Please answer all 4 questions above. 

Depending on how you want to proceed, we may need to look closely at watched topics & boards as well.

I'm open to input from others, but my personal suggestion is to keep data putzing to a minimum...  Specifically, if we find this data wasn't properly upgraded, my strong suggestion is to either (a) rerun the upgrader, or (b) find a way to provide defaults for converted users who are missing user_alerts_prefs.  I would abandon any thoughts of recovering watched topics & boards if that is missing.
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

smf_user_alerts_prefs - no entries for id_member 812 or 16384

SELECT COUNT(DISTINCT id_member) FROM smf_members; - 44061
SELECT COUNT(DISTINCT id_member) FROM smf_user_alerts_prefs; - 44064
SELECT COUNT(DISTINCT id_member) FROM smf_themes WHERE variable = 'auto_notify'; - 0

notify_regularity, notify_send_body, notify_types, notify_announcements - No

When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

The good news is that it looks like the upgrader migrated the notification preferences properly.

The bad news is I don't know what you should look at next...

Looking at my prod forum, I see it's not that unusual for users to have no preferences in user_alerts_prefs.  And I've never seen this error - so it's not as simple as they're just lacking alerts prefs. 

I suspect that entering values on their notifications screen will get rid of the issue for that particular user. 

It looks like both users had paid subscriptions.  Best guess now is that there is contradictory info somewhere, e.g., maybe subscriptions says "let them know they need to renew", but Scheduled Tasks poops out checking their email preferences.  Odd this isn't affecting anyone else though.  Normally ST just assumes the answer is no & doesn't send.

Anything else in common between those two? 

Any mods?  Especially ones affecting subscriptions or scheduled tasks?
A question worth asking is born in experience & driven by necessity. - Fripp

shawnb61

I just logged this as a bug: https://github.com/SimpleMachines/SMF/issues/8604

It looks like paid subs assumes it will always find user alerts prefs. 

Elsewhere in ScheduledTasks.php, it's checked first.  Looks like only paid subs skips the check.

So...  To fix, either explicitly add preferences for affected users, or, add an isset check before usage.
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

Errors so far -

id_member 680 - no subscription
id_member 812 - exp. 5-5-25
id_member 6333 - exp. 5-8-25
id_member 16384 - exp. 5-6-25
id_member 31624 - exp. 5-7-25


When in Emor, do as the Snamors.
                              - D. Lister

shawnb61

If they're all failing on the same 2 lines, I'd follow the suggestion above & test existence of the prefs with an isset on lines 1413 & 1416.
A question worth asking is born in experience & driven by necessity. - Fripp

Sir Osis of Liver

Why would paid subs scheduled task be failing for member who doesn't have a sub?

Will check the prefs soon as I get a minute.

When in Emor, do as the Snamors.
                              - D. Lister

Sir Osis of Liver

Don't see how this has anything to do with paid subs -


        // We need to do some shuffling to make this work properly.
        loadLanguage('EmailTemplates', $lang);
        $txt['emails']['happy_birthday'] = $birthdayEmails[$greeting];

        foreach ($recps as $recp)
        {
            $replacements = array(
                'REALNAME' => $recp['name'],
            );

            $emaildata = loadEmailTemplate('happy_birthday', $replacements, $lang, false);

            sendmail($recp['email'], $emaildata['subject'], $emaildata['body'], null, null, false, 4);

            // Try to stop a timeout, this would be bad...
            @set_time_limit(300);
            if (function_exists('apache_reset_timeout'))
                @apache_reset_timeout();

1413        }
    }

1416    // Flush the mail queue, just in case.
    AddMailQueue(true);

    return true;
}

When in Emor, do as the Snamors.
                              - D. Lister

 
Advertisement: