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

How to Set a Timeout for TdApi.DownloadFile in Java with tdlib? #3017

Closed
cdxf opened this issue Aug 11, 2024 · 5 comments
Closed

How to Set a Timeout for TdApi.DownloadFile in Java with tdlib? #3017

cdxf opened this issue Aug 11, 2024 · 5 comments

Comments

@cdxf
Copy link

cdxf commented Aug 11, 2024

I'm working with tdlib in Java and using the TdApi.DownloadFile method with synchronous = true to download files. However, I've encountered an issue where the process sometimes gets stuck indefinitely.

Is there a way to set a timeout for this API call to prevent it from hanging forever? If not, what would be the best approach to handle this situation effectively?

@levlam
Copy link
Contributor

levlam commented Aug 11, 2024

If you asked for synchronous download then you can't set a timeout for the request. To be able to cancel request you must use asynchronous file download and canceled it with TdApi.CancelDownloadFile.

By the way, calls to TDLib never hanging. The response to Client.send is always returned immediately and synchronous waiting for callback invocation is almost always a bug.

@cdxf
Copy link
Author

cdxf commented Aug 12, 2024

Thank for your answer.

For file download requests with specified offset and limit:

  1. How can I determine if the partial download is complete? Given that isDownloadingCompleted = false when the entire file isn't yet downloaded, should I check the downloadOffset, downloadedSize, and expectedSize values returned from updateFile to confirm completion?

  2. Is it possible to send multiple download requests for the same file with different offsets and limits concurrently, or must I wait for each request to complete before initiating another? I've attempted to send download requests simultaneously with varying offsets and limits, but they failed. What could be the reason for this issue?

local = LocalFile {
path = ""
canBeDownloaded = true
canBeDeleted = false
isDownloadingActive = true
isDownloadingCompleted = false
downloadOffset = 83886083
downloadedPrefixSize = 0
downloadedSize = 0
}

@levlam
Copy link
Contributor

levlam commented Aug 12, 2024

  1. The downloading isn't active whenever isDownloadingActive changes from true to false. Before that the last request is still running. Whenever it changes to false, you can check whether requested chunk is present. If it isn't then download was canceled or has failed.
  2. No, there can be only one concurrent download request for a file. There is no point in multiple requests: the user can watch the video only in one place.

@cdxf
Copy link
Author

cdxf commented Aug 13, 2024

I do not receive any UpdateFile with isDownloadingActive = false. Only when I close the client, then I receive the last UpdateFile with isDownloadingActive = false

I tried to download 1 file with 2 requests: (offset 2 limit 83886081) and (offset 83886083 limit 2000) one after another :
Here is the responses:

UpdateFile:
local = LocalFile {
path = "D:\project\td\example\java\tdlib-PGSMcP0c\temp_1a215d"
canBeDownloaded = true
canBeDeleted = true
isDownloadingActive = true
isDownloadingCompleted = false
downloadOffset = 2
downloadedPrefixSize = 83951614
downloadedSize = 83951616
}
Other responses with isDownloadingCompleted = false is omitted for brevity
UpdateFile:
local = LocalFile {
path = "D:\project\td\example\java\tdlib-PGSMcP0c\temp_1a215d"
canBeDownloaded = true
canBeDeleted = true
isDownloadingActive = true
isDownloadingCompleted = false
downloadOffset = 83886083
downloadedPrefixSize = 65533
downloadedSize = 83951616
}

I then do not receive any response further.
Then I Call TdApi.Close and received AuthorizationStateClosing update

Then receive the last UpdateFile
local = LocalFile {
path = "D:\project\td\example\java\tdlib-PGSMcP0c\temp_1a215d"
canBeDownloaded = true
canBeDeleted = true
isDownloadingActive = false
isDownloadingCompleted = false
downloadOffset = 83886083
downloadedPrefixSize = 65533
downloadedSize = 43384832
}

@levlam
Copy link
Contributor

levlam commented Aug 13, 2024

Could you send full log to https://t.me/tdlib_bot?

@levlam levlam closed this as completed Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants