Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Message records byte[] messy code Error decode! #1416

Closed
zhaieryuan opened this issue Mar 15, 2024 · 5 comments
Closed

The Message records byte[] messy code Error decode! #1416

zhaieryuan opened this issue Mar 15, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@zhaieryuan
Copy link

zhaieryuan commented Mar 15, 2024

我这边在message 消息中存储了二进制的json文本,当我去前台 queryMessage的时候,获取records 二进制数据进行,前端适配转换,出现了乱码,使用官网的develop分支进行的测试。而且这个问题是偶现的,怀疑是处理 rpc service中哪里使用了buffer 导致
image

客户端调用代码:
clientUserTwo.messageService.queryMessages({
ids: [3116933066495946752],
areGroupMessages: false,
areSystemMessages: false
}).then(res =>{
console.log("****************************************************************************");
// console.log(res);

            console.log(res.data[0].records);

            console.log(new TextDecoder().decode(res.data[0].records[0]));

            console.log(res.data[0].records[0].length);

        })

message 格式如下:

{
"isGroupMessage": false,
"isSystemMessage": false,
"text": "message00000001",
"recordBizStr": [
"{"type":1,"description":{"url":"[https://www.baidu.cn/tmp/im/1dc47ac1f206edd66ef89446761d8f82.jpeg](https://www.baidu.cn/tmp/im/1dc47ac1f206edd66ef89446761d8f82.jpeg/)","size":47719,"mimeType":"image/jpeg"}}"
],
"senderId": 10000,
"senderName": "senderName_25d652a4664e",
"targetId": 8453652352380108800
}

麻烦帮忙看下,感谢。

@zhaieryuan zhaieryuan changed the title The Message records byte[] The Message records byte[] messy code Error decode! Mar 15, 2024
@JamesChenX JamesChenX added status:pending status: confirming Confirming whether the issue is a bug or can be a new feature and removed status:pending labels Mar 15, 2024
@JamesChenX
Copy link
Member

It should not be the problem of the RPC service because if the RPC service encodes or decodes client messages incorrectly, turms clients will not have the chance to receive the responses and notifications.

I added some system tests about sending and receiving message records on my local computer, and all tests passed.
I also go through the workflow of sending and receiving message records from clients to servers and servers to clients, and they should work fine.

So I cannot reproduce the problems.


If you still encounter the problem, you can debug your clients and Turms servers yourself (that's why Turms is open-source).
After you find a message record is wrong. You can query the message document in MongoDB to check if the message document is stored incorrectly.
If the message record is stored incorrectly, you can debug the encoding and storing processing.
If not, you can debug the decoding processing to find out which step is wrong.
The debugging process should not be hard because you can reproduce the problem on your local, and you have all the source code and data in MongoDB.

@zhaieryuan
Copy link
Author

1、我这边本地环境
windows、mongodb 7.05、使用git仓库develop分支最新代码

2、本地复现,前几次请求同一个消息转码出来的二进制是正确的,如上截图标注了,连续的快速点击按钮十几次后,同一个消息的records部分就会出现乱码。这里再附上一张本地在调试的代码。

C83AB880-E66D-43e2-8849-C812910B6C0B

image

@JamesChenX JamesChenX added bug Something isn't working and removed status: confirming Confirming whether the issue is a bug or can be a new feature labels Mar 18, 2024
@zhaieryuan
Copy link
Author

zhaieryuan commented Mar 18, 2024

这里注释掉图一代码, 并添加图二方法,即解决了问题,请作者参考一下,并解释一下原因最好,感谢。

image

image

image

明文打印问题出现部分的乱码内容,如下,可以清晰的看到,ClientApiLogging.log 入侵了 返回的数据结构体

1710756352368_image-20240318113901388

@JamesChenX
Copy link
Member

JamesChenX commented Mar 18, 2024

Thanks for reporting and helping to pinpoint the bug.
I know now why it happens and will publish a bug fix and new release tomorrow or the day after tomorrow.

I will @you once published.

@JamesChenX
Copy link
Member

@zhaieryuan The bug has been fixed.
You can pull the latest code on the develop or master branch or pull the latest docker image to have a try.

The root cause is the bytes parameters of turms requests may be recycled while the server handler is handling the request. For details, please check the commit: 296afae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants