protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.14k stars 15.44k forks source link

[GPBMessage description] Crash #9511

Closed chengssir closed 2 years ago

chengssir commented 2 years ago

The network request is followed by output of the data, There were occasional crashes

Crashed: com.apple.NSURLSession-delegate 0 libobjc.A.dylib 0x20f8 objc_msgSend + 24 1 xxxxxxx 0xa70304 AppendTextFormatForMessage + 2023 (GPBUtilities.m:2023) 2 xxxxxxx 0xa70060 AppendTextFormatForMessage + 1880 (GPBUtilities.m:1880) 3 xxxxxxx 0xa6f8d8 GPBTextFormatForMessage + 2037 (GPBUtilities.m:2037) 4 xxxxxxx 0xa6809c -[GPBMessage description] + 2904 (GPBMessage.m:2904)

thomasvl commented 2 years ago

There isn't much to go on here. We don't have other reports of issues around description, but from the little bit you have, it does sound like a common problem in developer code - the classes generated for Messages are not safe to access from multiple threads if you are mutating them - i.e. - mutations must be done with exclusive access to the message and all messages reference in sub fields. My guess is your NSURLSession delegate is acting on the message, but something in that message graph is still being used/mutated by another thread, and that causes the thread trying to create the description to crash as the objects are changing underneath it.

chengssir commented 2 years ago

这里没有什么可做的。我们没有关于描述问题的其他报告,但从你所拥有的一点点来看,这听起来确实是开发人员代码中的一个常见问题——如果你改变它们,为 Messages 生成的类从多个线程访问是不安全的——即 - 必须通过独占访问消息和子字段中的所有消息引用来完成突变。我的猜测是您的 NSURLSession 委托正在对消息进行操作,但是该消息图中的某些内容仍在被另一个线程使用/更改,这会导致尝试创建描述的线程在其下方发生更改时崩溃。

NSURL baseUrl = [NSURL URLWithString:baseUrlStr]; NSURL url = [baseUrl URLByAppendingPathComponent:urlStr]; NSMutableURLRequest request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; if (parameters) { NSData data = [parameters data]; if (data) { request.HTTPBody = data; } }

parameters is a GPBMessage object

Crashed: com.apple.root.default-qos 0 libobjc.A.dylib 0x15e0 objc_msgSend + 32 1 xxxxxxx 0xa80070 -[GPBMessage writeToCodedOutputStream:] + 1310 (GPBMessage.m:1310) 2 xxxxxxx 0xa574c0 -[GPBCodedOutputStream writeMessageArray:values:] + 877 (GPBCodedOutputStream.m:877) 3 xxxxxxx 0xa80070 -[GPBMessage writeToCodedOutputStream:] + 1310 (GPBMessage.m:1310) 4 xxxxxxx 0xa7fd88 -[GPBMessage data] + 1259 (GPBMessage.m:1259)

thomasvl commented 2 years ago

That code is just building up the NSMutableRequest. The problem is going to be in your code that acts on the Message (parameters in that snippet); odds are it is being used from multiple threads while that request is being sent and the NSURLSession delegate is gets completion/status.