RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.39k stars 10.51k forks source link

E11000 duplicate key errors #24175

Open ankar84 opened 2 years ago

ankar84 commented 2 years ago

Description:

I see duplicate errors in logs that leads to errors like Invalid room [error-invalid-room] on createDirectMessage and getRoomByTypeAndName methods.

Steps to reproduce:

  1. Check logs for E11000 events per day

Expected behavior:

No duplicate errors in logs and normal works of Rocket.Chat server

Actual behavior:

E11000 errors

Server Setup Information:

Client Setup Information

Additional context

I don't know about specific impact for users from that errors, I guess users get some errors when they not expect to get them, for example when creating some chats.

Relevant logs:

{"level":50,"time":"2022-01-14T05:05:34.809Z","pid":9,"hostname":"d7d6e2fc85a8","name":"System","msg":"Exception while invoking method getRoomByTypeAndName 'Invalid room [error-invalid-room]'"}
{"level":50,"time":"2022-01-14T05:05:34.823Z","pid":9,"hostname":"d7d6e2fc85a8","name":"System","msg":"Exception while invoking method getRoomByTypeAndName 'Invalid room [error-invalid-room]'"}
{"level":50,"time":"2022-01-14T05:05:34.896Z","pid":9,"hostname":"d7d6e2fc85a8","name":"System","msg":"Exception while invoking method createDirectMessage 'E11000 duplicate key error collection: rocketchat.rocketchat_room index: _id_ dup key: { _id: \"YPevH7EkhFbCwTRD4ZZbxSB4gdT4k7fz7p\" }'"}
{"level":50,"time":"2022-01-14T05:05:34.941Z","pid":9,"hostname":"d7d6e2fc85a8","name":"System","msg":"Exception while invoking method getRoomByTypeAndName 'Invalid room [error-invalid-room]'"}
ankar84 commented 2 years ago

Related to https://github.com/RocketChat/Rocket.Chat/issues/22256#issuecomment-859074481 https://github.com/RocketChat/Rocket.Chat.Electron/issues/2241 Should be fixed in https://github.com/RocketChat/Rocket.Chat/pull/22944 but still appears in some cases in 4.4.0! I guess that Room not found error will appear instead new DM when E11000 duplicate in DB E11000 duplicate key error collection: rocketchat.rocketchat_room index: _id_ dup key: { _id: \"YPevH7EkhFbCwTRD4ZZbxSB4gdT4k7fz7p\"

@dougfabris @sampaiodiego that duplicate should be fixed in code with await or some other technic, I guess.

ankar84 commented 2 years ago

In DevTools I get this:

c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877 TypeError: Cannot read properties of undefined (reading '_id')
    at eval (/client/hooks/useRoomIcon.tsx:1)
    at Array.find (<anonymous>)
    at l (/client/hooks/useRoomIcon.tsx:1)
    at u (/client/views/room/Header/HeaderIconWithRoom.js:1)
    at Sa (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Ts (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at ef (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Zs (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Qs (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at $s (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
Ni @ c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877
c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:895 Uncaught TypeError: Cannot read properties of undefined (reading '_id')
    at eval (/client/hooks/useRoomIcon.tsx:1)
    at Array.find (<anonymous>)
    at l (/client/hooks/useRoomIcon.tsx:1)
    at u (/client/views/room/Header/HeaderIconWithRoom.js:1)
    at Sa (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Ts (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at ef (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Zs (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at Qs (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)
    at $s (c99d5589ba5d0c479bf85d7fca62ca304ae3da21.js?meteor_js_resource=true:877)

image image

ankar84 commented 2 years ago

Still an issue in 4.8.1

ankar84 commented 1 year ago

I still see some E11000 duplicate key errors, and still see Invalid room [error-invalid-room] on getRoomByTypeAndName method in server logs. But now I don't think that it's related.

ankar84 commented 1 year ago

Here is an example of recent E11000 duplicate key errors

Alert: MongoError: E11000 Message: {"level":50,"time":"2023-01-10T08:03:36.251Z","pid":9,"hostname":"8c03d1b9c354","name":"System","msg":"Exception while invoking method addUsersToRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "FWmpBPAEZKywWgpoq", u._id: "8tbDiQMgwNXPSknkT" }'"}
Alert: MongoError: E11000 Message: {"level":50,"time":"2023-01-10T10:05:16.252Z","pid":9,"hostname":"1746e3fdfea8","name":"System","msg":"Exception while invoking method joinRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "2ZWu62Wa257HoKdZT", u._id: "iaahKHwxKGCEBYN3o" }'"}
Alert: MongoError: E11000 Message: {"level":50,"time":"2023-01-12T15:41:18.670Z","pid":9,"hostname":"9aae10509561","name":"System","msg":"Exception while invoking method createDirectMessage 'E11000 duplicate key error collection: rocketchat.rocketchat_room index: id dup key: { _id: "N6Dg6NtBtDZ4fpyFyQ6JwomxYZ9QMo7ity" }'"} 
Alert: MongoError: E11000 Message: {"level":50,"time":"2022-12-28T10:57:57.170Z","pid":9,"hostname":"8cee435c3890","name":"System","msg":"Exception while invoking method addUsersToRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "5Ww8RWM7pGu2SLrji", u._id: "YZNKJ4vyb9DKWFe2n" }'"}
Alert: MongoError: E11000 Message: {"level":50,"time":"2022-12-23T08:33:30.959Z","pid":9,"hostname":"34bfc759d1f2","name":"System","msg":"Exception while invoking method addUsersToRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "fCDvJEpPRZBmgS2ze", u._id: "ZALcHpQXHwfYyGGAq" }'"}
Alert: MongoError: E11000 Message: {"level":50,"time":"2022-12-23T08:33:30.240Z","pid":9,"hostname":"34bfc759d1f2","name":"System","msg":"Exception while invoking method addUsersToRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "fCDvJEpPRZBmgS2ze", u._id: "X45MpenWAxJHDDq9M" }'"}
Alert: MongoError: E11000 Message: {"level":50,"time":"2022-12-23T06:56:16.071Z","pid":9,"hostname":"51f3d6ce1d23","name":"System","msg":"Exception while invoking method addUsersToRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "QMJ6XoD6hfEzQArM7", u._id: "ibKYtY6LqgHoybTRE" }'"} 
Alert: MongoError: E11000 Message: {"level":50,"time":"2022-12-22T06:41:23.063Z","pid":9,"hostname":"bda217a8fed1","name":"System","msg":"Exception while invoking method joinRoom 'E11000 duplicate key error collection: rocketchat.rocketchat_subscription index: rid_1_u._id_1 dup key: { rid: "cXQuZS9RkykzjY7kD", u._id: "nAQJqAD3yfgJ5kjo6" }'"}

@sampaiodiego can you check it?