{"record":{"id":"d7dc5f038e2149ce","repo":"RocketChat/Rocket.Chat","slug":"error-removing-visitor","errorCode":"error-removing-visitor","errorMessage":"An error ocurred while deleting visitor","messagePattern":"An error ocurred while deleting visitor","errorType":"exception","errorClass":"Meteor.Error","httpStatus":400,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/visitor.ts","lineNumber":158,"sourceCode":"\t\t).toArray();\n\n\t\t// if gdpr is enabled, bypass rooms check\n\t\tif (rooms?.length && !settings.get('Livechat_Allow_collect_and_store_HTTP_header_informations')) {\n\t\t\tthrow new Meteor.Error('visitor-has-open-rooms', 'Cannot remove visitors with opened rooms');\n\t\t}\n\n\t\tconst { _id } = visitor;\n\t\ttry {\n\t\t\tawait removeContactsByVisitorId({ _id });\n\t\t\treturn API.v1.success({\n\t\t\t\tvisitor: {\n\t\t\t\t\t_id,\n\t\t\t\t\tts: new Date().toISOString(),\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (e) {\n\t\t\tlivechatLogger.error({ msg: 'Error removing visitor', err: e });\n\t\t\tthrow new Meteor.Error('error-removing-visitor', 'An error ocurred while deleting visitor');\n\t\t}\n\t},\n});\n\nAPI.v1.addRoute(\n\t'livechat/visitor/:token/room',\n\t{ authRequired: true, permissionsRequired: ['view-livechat-manager'] },\n\t{\n\t\tasync get() {\n\t\t\tconst extraQuery = await callbacks.run('livechat.applyRoomRestrictions', {}, { userId: this.userId });\n\t\t\tconst rooms = await LivechatRooms.findOpenByVisitorToken(\n\t\t\t\tthis.urlParams.token,\n\t\t\t\t{\n\t\t\t\t\tprojection: {\n\t\t\t\t\t\tname: 1,\n\t\t\t\t\t\tt: 1,\n\t\t\t\t\t\tcl: 1,\n\t\t\t\t\t\tu: 1,","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/api/v1/omnichannel/visitor.ts#L140-L176","documentation":"Thrown by DELETE /api/v1/livechat/visitor/:token when removeContactsByVisitorId() throws while deleting the visitor's contact records. The visitor lookup and open-rooms check already passed, so this is a failure inside the deletion transaction itself. The original exception is logged (livechatLogger.error with msg 'Error removing visitor') before this generic error-livechat-removing-visitor is raised.","triggerScenarios":"Mongo write failure or timeout while removing linked contact documents; corrupted contact references (visitor id present in contacts but document shape unexpected); database permission/lock issues during peak load.","commonSituations":"Large visitors with many contact records timing out; replica set step-down mid-delete; partial deletes leaving orphaned contact entries that fail subsequent cleanup.","solutions":["Read the server log entry 'Error removing visitor' — the logged err field holds the actual Mongo error to act on","Retry the DELETE after the underlying DB issue clears (check Mongo health, disk, oplog)","If a specific contact document is corrupted, fix or remove it directly in the livechat_contacts collection, then retry","Verify the DB user has remove permissions on the contacts collection"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"const body = await (await fetch(`${server}/api/v1/livechat/visitor/${token}`, { method: 'DELETE' })).json();\nif (!body.success && body.error === 'error-removing-visitor') {\n  // server log 'Error removing visitor' holds the root cause; safe to retry after DB check\n  await notifyOps('visitor deletion failed — check livechatLogger');\n}","preventionTips":["Retry once after confirming DB health — the underlying removeContactsByVisitorId failure is often transient","Alert ops with the rid/token so they can pull the logged err detail","Keep contact collections indexed and healthy for large-scale deletions"],"tags":["livechat","visitor","delete","mongodb","contacts"],"backgroundTag":"database-delete-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}