td icon indicating copy to clipboard operation
td copied to clipboard

Sending previously sent requests

Open amoral-pony opened this issue 2 years ago • 4 comments

I'm starting to learn TDLib. I have a receiveUpdates_ method that receives updates and fills in certain fields. I have compiled and run the program several times, sending requests to td_api::getOption(...), td_api::close() e.t.c. Now the situation is worse: when calling, for example, clientManager_->send(clientId_, requestId++, nullptr), I get the requests I sent earlier. The tdlib directory did not appear in my working directory. Here is how it looks like:

void TelegramApi::receiveUpdates_()
{
  clientManager_->send(clientId_, ++requestId_, nullptr);
}

TelegramApi::TelegramApi()
{
  clientManager_ = td_api::make_object<ClientManager>();
  clientId_ = clientManager_->create_client_id();
  requestId_ = 0;

  receiveUpdates_();
  // updateAuthorizationState_();
}

Output:

[ 3][t 0][1702398218.087361812][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 4][1702398218.088156700][Td.cpp:2609][#1][!MultiTd]      Create Td with layer 167, database version 14 and version 51 on 4 threads
[ 3][t 4][1702398218.088364124][Td.cpp:4123][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "version"
  value = optionValueString {
    value = "1.8.22"
  }
}
[ 3][t 4][1702398218.088422298][Td.cpp:4123][#1][!Td][&td_requests]     Sending update: updateOption {
  name = "commit_hash"
  value = optionValueString {
    value = "3f00bebf63086020fa58ef0f0c9cc4692c30844e"
  }
}
[ 3][t 4][1702398218.088441848][Td.cpp:4123][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateWaitTdlibParameters {
  }
}
[ 3][t 0][1702398218.088460206][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7ff338000bb0
[ 3][t 4][1702398218.088475704][Td.cpp:3240][#1][!Td]   Receive Td::hangup
[ 2][t 4][1702398218.088497400][Td.cpp:3571][#1][!Td]   Close Td in state 0
[ 3][t 0][1702398218.088491439][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 4][1702398218.088513374][Td.cpp:4123][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateClosing {
  }
}
[ 3][t 0][1702398218.088523626][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7ff338001c80
[ 3][t 0][1702398218.088541746][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 0][1702398218.088551282][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7ff338001d20
[ 4][t 4][1702398218.088551998][Td.cpp:3388][#1][!Td]   Decrease request actor count to 0
[ 3][t 0][1702398218.088569641][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 4][1702398218.088573455][Td.cpp:3390][#1][!Td]   Have no request actors
[ 3][t 0][1702398218.088582992][Client.cpp:293][&td_requests]   End to wait for updates, returning object 1 0x7ff338001ed0
[ 4][t 4][1702398218.088600397][Td.cpp:3257][#1][!Td]   Decrease reference count to 0
[ 3][t 0][1702398218.088608980][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 4][1702398218.088618278][Td.cpp:4123][#1][!Td][&td_requests]     Sending update: updateAuthorizationState {
  authorization_state = authorizationStateClosed {
  }
}
[ 3][t 0][1702398218.088624715][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7ff338001f30
[ 3][t 4][1702398218.088642120][Td.cpp:3376][#1][!Td]   Stop Td
[ 3][t 0][1702398218.088652610][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 0][1702398218.088675022][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 0x7ff338001ff0
[ 3][t 0][1702398218.088687419][Client.cpp:280][&td_requests]   Begin to wait for updates with timeout 0.100000
[ 3][t 0][1702398218.088724374][Client.cpp:293][&td_requests]   End to wait for updates, returning object 0 (nil)

How do I prevent old requests from being sent?

amoral-pony avatar Dec 12 '23 16:12 amoral-pony

What do you mean by "I get the requests I sent earlier"? send returns nothing, so you can't receive anything from it.

In the log you create a TDLib instance, which is closed immediately, because corresponding ClientManager is destroyed.

levlam avatar Dec 13 '23 22:12 levlam

Is it normal that I send an empty request and TDLib sends an update for updateOption, updateAuthorizationState, then repeatedly accepts the updates and closes, even though there is nothing in the program other than sending an empty request. When I tried sending a query with some object and receiving a response via receive(), the response did not change depending on the query.

amoral-pony avatar Dec 14 '23 14:12 amoral-pony

TDLib can send updates any time whenever appropriate. It has closed, because the corresponding ClientManager was destroyed and your app lost ability to send request to it, or receive updates and responses from the instance.

levlam avatar Dec 14 '23 15:12 levlam

I was sending and receiving requests via the receiveUpdates_() method, so the ClientManager was not destroyed at that point.

amoral-pony avatar Dec 14 '23 21:12 amoral-pony