Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

Sometimes it cannot return channel info via the rest API after create channel success.

Open FTDJerry opened this issue 9 years ago • 3 comments

Description:

I have created channel via the rest API '/api/v1/channels.create'. It is success, but the response doesn't have channel info sometimes:

{
    "success": true
}

Correct return is:

{
    "channel": {
       ...
    },
    "success": true
}

But when I use the Administrator user, it returns channel info every time. Anybody know why? Thanks!

Server Setup Information:

  • Version of Rocket.Chat Server: 0.57.2
  • Operating System: Ubuntu 14.04
  • Deployment Method(snap/docker/tar/etc): tar
  • Number of Running Instances: 1
  • DB Replicaset Oplog:
  • Node Version: 4.6.1

FTDJerry avatar Jul 29 '17 07:07 FTDJerry

Closing as I can't reproduce. I tested with both an administrator and a regular user, both times the resulting object contained the success along with channel. Please open again should you determine how to reproduce this...

graywolf336 avatar Jul 31 '17 23:07 graywolf336

Sorry, I can't find how to reproduce this, but it appeared every several times when I had called the create channel service. So I tried to add log in this API.

First, channel created success in fact. So I thought in the return method:

channel.js

return RocketChat.API.v1.success({
	channel: RocketChat.models.Rooms.findOneById(id.rid, { fields: RocketChat.API.v1.defaultFieldsToExclude })
});

_Base.js

findOneById() {
	try {
		return this[this.origin].findOneById(...arguments);
	} catch (e) {
		console.error('Exception on find', e, ...arguments);
	}
}

I had found that it used the cache to get the result default. Then I added log to see the result:

findOneById() {
	try {
		console.error('db=======>' + this['_db'].findOneById(...arguments), null, ...arguments);
		console.error('cache=======>' + this['cache'].findOneById(...arguments), null, ...arguments);
		return this[this.origin].findOneById(...arguments);
	} catch (e) {
		console.error('Exception on find', e, ...arguments);
	}
}

The log as follow when the response didn't have channel info :

db=======>[object Object] null MvR57ZoTLS5dbCtN4 { fields: { joinCode: 0, '$loki': 0, meta: 0 } }
cache=======>undefined null MvR57ZoTLS5dbCtN4 { fields: { joinCode: 0, '$loki': 0, meta: 0 } }

I think that the new channel didn't add to the cache sometimes so it can't return the result.

@graywolf336 Could you help me to deal with this problem, or how to get result via the db?

Thanks!

FTDJerry avatar Aug 03 '17 08:08 FTDJerry

I am assigning this one to @rodrigok since it is a cache related issue.

graywolf336 avatar Aug 03 '17 16:08 graywolf336