generated from Warchant/cmake-hunter-seed
-
Notifications
You must be signed in to change notification settings - Fork 36
Reconnect socket && worker ping #600
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
Open
Elestrias
wants to merge
13
commits into
master
Choose a base branch
from
RemoteWorkerPingRecconect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ace090
Recconct socket && worker ping
Elestrias 59e534c
workerfix
Elestrias 16b8cd5
recoonect fix
Elestrias 1e08815
pr fixes
Elestrias 5c5067a
duplicate worker fix
Elestrias 566d6d2
Writing status move
Elestrias 07085f0
Merge branch 'master' into RemoteWorkerPingRecconect
Elestrias 3b1decb
check fixes
Elestrias b52f975
Merge branch 'RemoteWorkerPingRecconect' of github.com:filecoin-proje…
Elestrias 9e79b58
Merge branch 'master' into RemoteWorkerPingRecconect
Elestrias 8e0d911
Update core/sector_storage/impl/manager_impl.cpp
Elestrias a73b6dc
fix manager
Elestrias 48facdb
Merge branch 'RemoteWorkerPingRecconect' of github.com:filecoin-proje…
Elestrias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,25 +37,26 @@ namespace fc::api::rpc { | |
return connect(ip, port, target, token); | ||
} | ||
|
||
outcome::result<void> Client::connect(const std::string &host, | ||
const std::string &port, | ||
const std::string &target, | ||
const std::string &token) { | ||
outcome::result<void> Client::connect(const std::string &host, | ||
const std::string &port, | ||
const std::string &target, | ||
const std::string &token) { | ||
boost::system::error_code ec; | ||
socket.next_layer().connect({boost::asio::ip::make_address(host), | ||
boost::lexical_cast<uint16_t>(port)}, | ||
ec); | ||
socket->next_layer().connect({boost::asio::ip::make_address(host), | ||
boost::lexical_cast<uint16_t>(port)}, | ||
ec); | ||
if (ec) { | ||
return ec; | ||
} | ||
if (not token.empty()) { | ||
socket.set_option( | ||
socket->set_option( | ||
boost::beast::websocket::stream_base::decorator([&](auto &req) { | ||
req.set(boost::beast::http::field::authorization, | ||
"Bearer " + token); | ||
})); | ||
} | ||
socket.handshake(host, target, ec); | ||
socket->handshake(host, target, ec); | ||
client_data = ClientData{host, port, target, token}; | ||
if (ec) { | ||
return ec; | ||
} | ||
|
@@ -87,27 +88,28 @@ namespace fc::api::rpc { | |
} | ||
} | ||
chans.clear(); | ||
reconnect(3, std::chrono::seconds(5)); | ||
} | ||
|
||
void Client::_flush() { | ||
if (!writing && !write_queue.empty()) { | ||
if (!writing && !write_queue.empty() && not reconnecting) { | ||
auto &[id, buffer] = write_queue.front(); | ||
writing = true; | ||
socket.async_write(boost::asio::buffer(buffer.data(), buffer.size()), | ||
[=](auto &&ec, auto) { | ||
std::lock_guard lock{mutex}; | ||
if (ec) { | ||
return _error(ec); | ||
} | ||
writing = false; | ||
write_queue.pop(); | ||
_flush(); | ||
}); | ||
socket->async_write(boost::asio::buffer(buffer.data(), buffer.size()), | ||
[=](auto &&ec, auto) { | ||
std::lock_guard lock{mutex}; | ||
if (ec) { | ||
return _error(ec); | ||
} | ||
writing = false; | ||
turuslan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
write_queue.pop(); | ||
_flush(); | ||
}); | ||
} | ||
} | ||
|
||
void Client::_read() { | ||
socket.async_read(buffer, [=](auto &&ec, auto) { | ||
socket->async_read(buffer, [=](auto &&ec, auto) { | ||
if (ec) { | ||
std::lock_guard lock{mutex}; | ||
return _error(ec); | ||
|
@@ -185,4 +187,36 @@ namespace fc::api::rpc { | |
} | ||
} | ||
} | ||
|
||
void Client::reconnect(int counter, std::chrono::milliseconds wait) { | ||
if (reconnecting) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it thread-safe? |
||
reconnecting = true; | ||
bool rec_status{false}; | ||
logger_->info( | ||
"Starting reconnect to {}:{}", client_data.host, client_data.port); | ||
for (int i = 0; i < counter; i++) { | ||
std::this_thread::sleep_for(wait); | ||
socket.reset(); | ||
socket.emplace(io); | ||
auto res = connect(client_data.host, | ||
client_data.port, | ||
client_data.target, | ||
client_data.token); | ||
turuslan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (not res.has_error()) { | ||
rec_status = true; | ||
break; | ||
} | ||
} | ||
reconnecting = false; | ||
if (rec_status) { | ||
logger_->info("Reconnect to {}:{} was successful", | ||
client_data.host, | ||
client_data.port); | ||
_flush(); | ||
} else { | ||
logger_->error("Reconnect to {}:{} have been failed", | ||
client_data.host, | ||
client_data.port); | ||
} | ||
} | ||
} // namespace fc::api::rpc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -904,4 +904,7 @@ namespace fc::sector_storage { | |||||||||||
|
||||||||||||
return call_id; | ||||||||||||
} | ||||||||||||
void LocalWorker::ping(std::function<void(const bool resp)> cb) { | ||||||||||||
Comment on lines
910
to
+911
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
cb(true); | ||||||||||||
} | ||||||||||||
} // namespace fc::sector_storage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.