Skip to content

Commit 06b4787

Browse files
committed
Add timeouts to executor socket
1 parent fccf6b5 commit 06b4787

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

api/include/apihandler.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,15 @@ public slots:
436436
const std::string& p_exec_ip, const std::string& p_exec_cmdline)
437437
: blockchain_(p_blockchain)
438438
, solver_(solver)
439-
, executorTransport_(new ::apache::thrift::transport::TBufferedTransport(
440-
::apache::thrift::stdcxx::make_shared<::apache::thrift::transport::TSocket>(p_exec_ip, p_exec_port)))
439+
, socket_(::apache::thrift::stdcxx::make_shared<::apache::thrift::transport::TSocket>(p_exec_ip, p_exec_port))
440+
, executorTransport_(new ::apache::thrift::transport::TBufferedTransport(socket_))
441441
, origExecutor_(
442442
std::make_unique<executor::ContractExecutorConcurrentClient>(::apache::thrift::stdcxx::make_shared<apache::thrift::protocol::TBinaryProtocol>(executorTransport_))) {
443443
std::string executorCmdline = p_exec_cmdline;
444444

445+
socket_->setSendTimeout(kSendTimeout);
446+
socket_->setRecvTimeout(kReceiveTimeout);
447+
445448
if (executorCmdline.empty()) {
446449
cswarning() << "Executor command line args are empty, process would not be created";
447450
return;
@@ -561,7 +564,10 @@ public slots:
561564
private:
562565
const BlockChain& blockchain_;
563566
const cs::SolverCore& solver_;
567+
568+
::apache::thrift::stdcxx::shared_ptr<::apache::thrift::transport::TSocket> socket_;
564569
::apache::thrift::stdcxx::shared_ptr<::apache::thrift::transport::TTransport> executorTransport_;
570+
565571
std::unique_ptr<executor::ContractExecutorConcurrentClient> origExecutor_;
566572
std::unique_ptr<cs::Process> executorProcess_;
567573

@@ -577,8 +583,13 @@ public slots:
577583

578584
std::condition_variable cvErrorConnect_;
579585
std::atomic_bool requestStop_{ false };
586+
580587
const int16_t EXECUTOR_VERSION = 2;
581588

589+
// timeout in ms
590+
const int kSendTimeout = 4000;
591+
const int kReceiveTimeout = 4000;
592+
582593
// temporary solution?
583594
std::mutex callExecutorLock_;
584595
};

0 commit comments

Comments
 (0)