getodk / getodk/central

Reap singleUse actors

Open
#1,238 1 comment 1 reaction 0 assignees View on GitHub
backend
Dominant language
JavaScript
Stars
226
Forks
235
Avg merge
2d 22h
Merged PRs (30d)
19

Description

`singleUse` actors are for internal use:

- When a password reset is initiated, a `singleUse` actor is created and assigned the `pwreset` role. A 24-hour session is created for the actor, and the session's token is sent over email as part of a password reset URL.
- When a form is published, a `singleUse` actor is created and assigned the `formview` role in order to provide Enketo temporary access to the form. A 15-minute session is created for the actor.
- Formerly, Google Drive backups created `singleUse` actors. Google Drive backups have been removed.

In some cases, `singleUse` actors are deleted:

- If an actor with a `pwreset` assignment is used to change a password, the actor is then "consumed" (`Actors.consume()`).
- All `singleUse` actors created for Google Drive backups should be deleted now that that functionality has been removed.

However, I think that in other cases, `singleUse` actors are not deleted:

- 24 hours elapse before a password reset token is used. In that case, a new password reset must be requested. Yet the old `singleUse` actor is never deleted.
- Actors with a `formview` assignment are never deleted.

Looking at the QA server, I see:

- A smaller number of non-deleted actors with a `pwreset` assignment
- A much larger number of non-deleted actors with a `formview` assignment. A larger number makes sense given that every form will be associated with at least one `formview` actor. (It could be more than one if a request to Enketo fails.)
- I see a number of `singleUse` actors that are not deleted, yet do not have an assignment. In all cases, their `displayName` contains "Enketo sync token". I assume these correspond to deleted forms.
- Some deleted `singleUse` actors correspond to Google Drive backups. That's expected.

Given that these `singleUse` actors are tightly coupled with a single session, I think we should consider deleting them when we reap sessions (lib/task/reap-sessions.js). Specifically, if a session is expired, and the session was for a `singleUse` actor, then delete both the session and the actor.

We could also consider writing a migration to delete existing `singleUse` actors that are unneeded. To me, that seems lower-priority but still worthwhile.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in lib/task/reap-sessions.js and trace how expired sessions and their actors are handled. Define the cleanup behavior for expired sessions belonging to singleUse actors, including deletion of the associated actor, and assess separately whether existing unneeded actors require a migration.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.