Skip to content

Commit

Permalink
Limit the number of threads to 127 (#1111)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpyCheese authored Aug 16, 2024
1 parent 9661676 commit 06515c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions dht-server/dht-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,15 +1231,19 @@ int main(int argc, char *argv[]) {
});
td::uint32 threads = 7;
p.add_checked_option(
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) {
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice arg) {
td::int32 v;
try {
v = std::stoi(fname.str());
v = std::stoi(arg.str());
} catch (...) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number");
}
if (v < 1 || v > 256) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]");
if (v <= 0) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be > 0");
}
if (v > 127) {
LOG(WARNING) << "`--threads " << v << "` is too big, effective value will be 127";
v = 127;
}
threads = v;
return td::Status::OK();
Expand Down
12 changes: 8 additions & 4 deletions validator-engine/validator-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4157,15 +4157,19 @@ int main(int argc, char *argv[]) {
});
td::uint32 threads = 7;
p.add_checked_option(
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice fname) {
't', "threads", PSTRING() << "number of threads (default=" << threads << ")", [&](td::Slice arg) {
td::int32 v;
try {
v = std::stoi(fname.str());
v = std::stoi(arg.str());
} catch (...) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: not a number");
}
if (v < 1 || v > 256) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be in range [1..256]");
if (v <= 0) {
return td::Status::Error(ton::ErrorCode::error, "bad value for --threads: should be > 0");
}
if (v > 127) {
LOG(WARNING) << "`--threads " << v << "` is too big, effective value will be 127";
v = 127;
}
threads = v;
return td::Status::OK();
Expand Down

0 comments on commit 06515c3

Please sign in to comment.