Fix calling file load callbacks on closing.

GitOrigin-RevId: 1b1bad8bdd255332cdca2ece6cffd3ce16cfc7e2
This commit is contained in:
levlam 2018-05-24 01:30:47 +03:00
parent 0ad0079900
commit 3f8be23cd2
5 changed files with 39 additions and 33 deletions

View File

@ -6781,8 +6781,6 @@ void ContactsManager::on_update_user_links(UserId user_id, tl_object_ptr<telegra
}
void ContactsManager::on_update_user_links(User *u, UserId user_id, LinkState outbound, LinkState inbound) {
LOG(DEBUG) << "Update " << user_id << " links from (" << u->outbound << ", " << u->inbound << ") to (" << outbound
<< ", " << inbound << ")";
UserId my_id = get_my_id("on_update_user_links");
if (user_id == my_id) {
if (outbound == LinkState::None && !td_->auth_manager_->is_bot()) {
@ -6791,6 +6789,8 @@ void ContactsManager::on_update_user_links(User *u, UserId user_id, LinkState ou
inbound = outbound;
}
LOG(DEBUG) << "Update " << user_id << " links from (" << u->outbound << ", " << u->inbound << ") to (" << outbound
<< ", " << inbound << ")";
bool need_send_update = false;
if (outbound != u->outbound && outbound != LinkState::Unknown) {
need_send_update |= outbound != LinkState::None || u->outbound != LinkState::Unknown;

View File

@ -39,7 +39,7 @@ class GetSecureValue : public NetQueryCallback {
optional<EncryptedSecureValue> encrypted_secure_value_;
optional<secure_storage::Secret> secret_;
void on_error(Status status);
void on_error(Status error);
void on_secret(Result<secure_storage::Secret> r_secret, bool dummy);
void loop() override;
void start_up() override;
@ -58,7 +58,7 @@ class GetAllSecureValues : public NetQueryCallback {
optional<vector<EncryptedSecureValue>> encrypted_secure_values_;
optional<secure_storage::Secret> secret_;
void on_error(Status status);
void on_error(Status error);
void on_secret(Result<secure_storage::Secret> r_secret, bool dummy);
void loop() override;
void start_up() override;
@ -98,13 +98,13 @@ class SetSecureValue : public NetQueryCallback {
void on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file) override;
void on_upload_encrypted_ok(FileId file_id, tl_object_ptr<telegram_api::InputEncryptedFile> input_file) override;
void on_upload_secure_ok(FileId file_id, tl_object_ptr<telegram_api::InputSecureFile> input_file) override;
void on_upload_error(FileId file_id, Status error) override;
void on_upload_error(FileId file_id, Status status) override;
};
void on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::InputSecureFile> input_file);
void on_upload_error(FileId file_id, Status error);
void on_upload_error(FileId file_id, Status status);
void on_error(Status status);
void on_error(Status error);
void on_secret(Result<secure_storage::Secret> r_secret, bool x);
@ -157,11 +157,11 @@ GetSecureValue::GetSecureValue(ActorShared<> parent, std::string password, Secur
: parent_(std::move(parent)), password_(std::move(password)), type_(type), promise_(std::move(promise)) {
}
void GetSecureValue::on_error(Status status) {
if (status.code() != 0) {
promise_.set_error(std::move(status));
void GetSecureValue::on_error(Status error) {
if (error.code() != 0) {
promise_.set_error(std::move(error));
} else {
promise_.set_error(Status::Error(400, status.message()));
promise_.set_error(Status::Error(400, error.message()));
}
stop();
}
@ -230,11 +230,11 @@ GetAllSecureValues::GetAllSecureValues(ActorShared<> parent, std::string passwor
: parent_(std::move(parent)), password_(std::move(password)), promise_(std::move(promise)) {
}
void GetAllSecureValues::on_error(Status status) {
if (status.code() != 0) {
promise_.set_error(std::move(status));
void GetAllSecureValues::on_error(Status error) {
if (error.code() != 0) {
promise_.set_error(std::move(error));
} else {
promise_.set_error(Status::Error(400, status.message()));
promise_.set_error(Status::Error(400, error.message()));
}
stop();
}
@ -302,14 +302,17 @@ void SetSecureValue::UploadCallback::on_upload_ok(FileId file_id, tl_object_ptr<
CHECK(input_file == nullptr);
send_closure_later(actor_id_, &SetSecureValue::on_upload_ok, file_id, nullptr);
}
void SetSecureValue::UploadCallback::on_upload_encrypted_ok(
FileId file_id, tl_object_ptr<telegram_api::InputEncryptedFile> input_file) {
UNREACHABLE();
}
void SetSecureValue::UploadCallback::on_upload_secure_ok(FileId file_id,
tl_object_ptr<telegram_api::InputSecureFile> input_file) {
send_closure_later(actor_id_, &SetSecureValue::on_upload_ok, file_id, std::move(input_file));
}
void SetSecureValue::UploadCallback::on_upload_error(FileId file_id, Status error) {
send_closure_later(actor_id_, &SetSecureValue::on_upload_error, file_id, std::move(error));
}
@ -337,18 +340,18 @@ void SetSecureValue::on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::In
info.input_file = std::move(input_file);
CHECK(files_left_to_upload_ != 0);
files_left_to_upload_--;
return loop();
loop();
}
void SetSecureValue::on_upload_error(FileId file_id, Status error) {
return on_error(std::move(error));
on_error(std::move(error));
}
void SetSecureValue::on_error(Status status) {
if (status.code() != 0) {
promise_.set_error(std::move(status));
void SetSecureValue::on_error(Status error) {
if (error.code() != 0) {
promise_.set_error(std::move(error));
} else {
promise_.set_error(Status::Error(400, status.message()));
promise_.set_error(Status::Error(400, error.message()));
}
stop();
}
@ -603,11 +606,11 @@ class GetPassportAuthorizationForm : public NetQueryCallback {
loop();
}
void on_error(Status status) {
if (status.code() != 0) {
promise_.set_error(std::move(status));
void on_error(Status error) {
if (error.code() != 0) {
promise_.set_error(std::move(error));
} else {
promise_.set_error(Status::Error(400, status.message()));
promise_.set_error(Status::Error(400, error.message()));
}
stop();
}

View File

@ -266,12 +266,9 @@ void FileLoadManager::hangup_shared() {
}
void FileLoadManager::loop() {
if (stop_flag_) {
if (nodes_container_.empty()) {
if (stop_flag_ && nodes_container_.empty()) {
stop();
}
return;
}
}
void FileLoadManager::close_node(NodeId node_id) {

View File

@ -10,7 +10,6 @@
#include "td/telegram/files/FileLoaderUtils.h"
#include "td/telegram/files/FileLocation.h"
#include "td/telegram/files/FileUploader.h"
#include "td/telegram/Global.h"
#include "td/telegram/misc.h"
#include "td/telegram/Td.h"
@ -2309,7 +2308,7 @@ void FileManager::on_error(QueryId query_id, Status status) {
return;
}
if (query.type_ == Query::UploadByHash) {
if (query.type_ == Query::UploadByHash && !G()->close_flag()) {
LOG(INFO) << "Upload By Hash failed: " << status << ", restart upload";
node->get_by_hash_ = false;
run_upload(node, {});
@ -2322,7 +2321,7 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type,
SCOPE_EXIT {
try_flush_node(node);
};
if (status.code() != 1) {
if (status.code() != 1 && !G()->close_flag()) {
LOG(WARNING) << "Failed to upload/download/generate file: " << status << ". Query type = " << type
<< ". File type is " << file_type_name[static_cast<int32>(FileView(node).get_type())];
if (status.code() == 0) {
@ -2421,6 +2420,12 @@ void FileManager::hangup() {
file_db_.reset();
file_generate_manager_.reset();
file_load_manager_.reset();
while (!queries_container_.empty()) {
auto ids = queries_container_.ids();
for (auto id : ids) {
on_error(id, Status::Error(500, "Internal Server Error: closing"));
}
}
stop();
}

View File

@ -185,6 +185,7 @@ Status FileUploader::on_ok(int64 size) {
}
return Status::OK();
}
void FileUploader::on_error(Status status) {
fd_.close();
if (is_temp_) {