LDAP sync user cannot be added to default channel


I receive this error when take a trial on LDAP sync function

Error: server.js:204 LDAPSync ➔ error Error creating user BulkWriteError: E11000 duplicate key error collection: meteor.rocketchat_subscription index: id dup key: { _id: “aNLpM9qHndnqANgNx” }

Step to preproduce:

  • Turn on LDAP with setting

Enable = true
Login Fallback = true
Find user after login = true
Host = example.local
Port = 8075
Base DN = dc=example,dc=org

User DN = cn=admin,dc=example,dc=org
Password = 12345

Username Field = uid
User Data Field Map = {“giveName”: “name”, “mail”: “email”}
Sync User Avatar = true

#User Search
Search Field = uid

  • Save changes
  • Execute Synchronization Now

Error discover

I find out errors happen at this file: addUserToDefaultChannels.js

  • Function: createWithRoomAndUser (line this.insert(subscription))
  • Function: createUserJoinWithRoomIdAndUser

I have log the subscriptions and message data to the console and see that the _id is not input.
However, the _id is duplicated in the insert method by mongodb.
I sync 4 users with username, password, email, name, …

Server Setup Information

  • Version of Rocket.Chat Server: 3.7.0-develop
  • Operating System: Linux mint
  • Deployment Method: Mannual install
  • Number of Running Instances: 1
  • DB Replicaset Oplog: default
  • NodeJS Version: 12.18.3
  • MongoDB Version: 4.2.8
  • Proxy: no
  • Firewalls involved:no

I also found in bug in the version of Rocket Chat Server: 3.4.2
with the Server Setup information is default by Rocket.Chat

Any additional Information

Error log:

A sample user’s attributes:

I have the same error too. In my case, LDAP’s user has been synchronized but only user, password are not.

My current fix is:

  • In Accounts.insertUserDoc, I call function addUserToDefaultChannels directly instead of using the below code:
Meteor.runAsUser(_id, function() {
    return Meteor.call('joinDefaultChannels', options.joinDefaultChannelsSilenced);
1 Like

Thanks for shared.
So when you are using some code like addUserToDefaultChannels you can login RocketChat via LDAP user right now?

Yes, I import and use that function directly.

I don’t know why when I use runAsUser, and when I sync at least 2 users.

  • The first one is always working properly.
  • The second one is always crashed because of duplicated ID. Its ID is taken from the first one subscription ID (???). Even I input the subscription _id, the creation of adding message (because of not silenced) is still failed due to the duplicated key (???)
1 Like