tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.2k stars 1.46k forks source link

iOS app crashes on td_json_client_destroy #594

Closed Demetriy closed 5 years ago

Demetriy commented 5 years ago

I'm using modified example of this code https://github.com/tdlib/td/blob/master/example/swift/src/main.swift, previously in tdlib 1.3 when user drops app in background i destroyed client with td_json_client_destroy(client), but in 1.4 i'm started to get messages: [ 0][t 0][1560468306.749094009][Client.cpp:269] Check !is_locked failed

How can i properly close connection on app background and then create it again in 1.4?

levlam commented 5 years ago

This is a sanity check that td_json_client_receive is not run while the client is being destroyed. td_json_client_destroy completly destroys a client, so the client must not be used from other threads at that time. To properly close the client, you need to call close method and wait for updateAuthorizationState with authorizationStateClosed. After that you can stop to call td_json_client_receive and can destroy the client via td_json_client_destroy.

Demetriy commented 5 years ago

Thanks! I solved my problem with your help :)

chairus commented 4 years ago

@levlam Just a question. Telegram clients created in different threads are completely independent from one another right? i.e. one thread closing/destroying it's client doesn't affect other clients in different thread that were created independently.

chairus commented 4 years ago

also if a file is currently being downloaded and the client is destroyed does it also result in that Check !is_locked error?

levlam commented 4 years ago

@chairus All TDLib clients are independent and doesn't affect each other, except competing for system resources. Client's thread doesn't matter.

Check !is_locked is always an application error, which tries to destroy the client while it is still being used in another thread. It doesn't matter whether some download file or other pending operation is in progress.