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
- Create a session with several linked questions.
- Trigger DELETE /api/sessions/:id.
- 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).
- 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
Bug Description
deleteSession(backend/controllers/sessionController.js) runs two independent writes with no transaction:Question.deleteMany({ session: session._id })followed bysession.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
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