Skip to content

[Bug]: deleteSession is non-transactional — partial failure orphans questions or leaves sessions undeleted #373

Description

@hariom888

Bug Description

deleteSession (backend/controllers/sessionController.js) runs two independent writes with no transaction: Question.deleteMany({ session: session._id }) followed by session.deleteOne(). If the second operation fails or the process is interrupted between the two calls, the two collections are left in an inconsistent state relative to each other.

Steps to Reproduce

  1. Create a session with several linked questions.
  2. Trigger DELETE /api/sessions/:id.
  3. Simulate a failure between the two write operations (e.g. force session.deleteOne() to throw via a validation hook, DB blip, or process kill mid-request).
  4. Inspect the Session and Question collections afterward.

Expected Behavior

Either both the session and its linked questions are deleted together, or neither is — the deletion should be atomic so the two collections never disagree.

Actual Behavior

If failure occurs after Question.deleteMany succeeds but before session.deleteOne() commits, the Session document remains but its linked questions are gone, and getSessionById/getMySessions silently populate an empty questions array with no indication data was lost.

Severity

High

Screenshots / Screen Recording

No response

Browser

No response

Operating System

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions