Skip to content

Reinstalling an application creates a ghost of its schedules #239

@Jiralite

Description

@Jiralite

Reddit does not properly clean up apps when they are uninstalled.

You can reproduce this by adding a schedule in your devvit.json. like so:

"scheduler": {
	"tasks": {
		"daily-guides": {
			"endpoint": "/internal/scheduler/daily-guides",
			"cron": "* * * * *"
		}
	}
},

Then, configure a route to handle it:

// index.ts.
router.post("/internal/scheduler/daily-guides", scheduleFunction);
// Maybe in another file...
import { context, reddit, redis } from "@devvit/web/server";

export async function scheduleFunction() {
	const widgetId = await redis.get('schedule-key');

	if (!widgetId) {
		console.info("Widget not found. Creating one.");

		const widget = await reddit.addWidget({
			subreddit: context.subredditName,
			type: "textarea",
			shortName: "Countdown",
			text: "test",
		});

		await redis.set('schedule-key', widget.id);
		return;
	}

	await reddit.updateWidget({
		subreddit: context.subredditName,
		type: "textarea",
		id: widgetId,
		shortName: "Countdown",
		text: "test",
	});
}

Then:

  1. Install the app to a subreddit
  2. Uninstall it after several minutes
  3. Install the app to the aforementioned subreddit

After a few minutes after step 3, you'll have a mod log like this:

Image

It looks like the first scheduled has returned and it is updating the widget from the id stored in Redis somehow. It shouldn't know that it is still there. Then, it starts a new schedule from installation, creating a widget since it doesn't know anything about the subreddit which is expected behaviour, stores the widget id in Redis, and proceeds to edit it. This leads to 2 widgets.

If you run await scheduler.listJobs();, only 1 job would be listed–the job you started your application with to log that in the first place–not 2. The other schedule is now a ghost–you cannot find it, you cannot stop it, you cannot uninstall your application as a workaround as demonstrated above... it's totally broken.

Also, I'd appreciate if a lurking administrator can resolve my prior schedules (my application is in the above screenshot)!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions