Skip to content

Commit

Permalink
dispose session_store on IPC/TCP disconnect request
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Apr 22, 2024
1 parent acf5c38 commit f7c1a0b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/tateyama/endpoint/ipc/bootstrap/ipc_worker.cpp
Expand Up @@ -53,6 +53,7 @@ void Worker::do_work() {
auto h = request_wire_container_->peep();
if (h.get_length() == 0 && h.get_idx() == tateyama::common::wire::message_header::null_request) {
if (request_wire_container_->terminate_requested()) {
dispose_session_store();
request_shutdown(tateyama::session::shutdown_request_type::forceful);
}
care_reqreses();
Expand Down
6 changes: 6 additions & 0 deletions src/tateyama/endpoint/stream/bootstrap/stream_worker.cpp
Expand Up @@ -117,7 +117,13 @@ void stream_worker::do_work()
}
continue;

case tateyama::endpoint::stream::stream_socket::await_result::termination_request:
dispose_session_store();
session_stream_->send_session_bye_ok();
continue;

default: // some error
dispose_session_store();
break;
}
break;
Expand Down
14 changes: 11 additions & 3 deletions src/tateyama/endpoint/stream/stream.h
Expand Up @@ -101,6 +101,11 @@ class stream_socket
*/
socket_closed,

/**
* @brief the client has sent a request of session close.
*/
termination_request,

/**
* @brief the message received is in an illegal format.
*/
Expand Down Expand Up @@ -137,6 +142,11 @@ class stream_socket
DVLOG_LP(log_trace) << "<-- RESPONSE_RESULT_SET_BYE " << static_cast<std::uint32_t>(slot);
send_response(RESPONSE_RESULT_SET_BYE, slot, "");
}
void send_session_bye_ok() { // for RESPONSE_SESSION_BYE_OK
DVLOG_LP(log_trace) << "<-- RESPONSE_SESSION_BYE_OK ";
send_response(RESPONSE_SESSION_BYE_OK, 0, "", true);
}

void send(std::uint16_t slot, unsigned char writer, std::string_view payload) { // for RESPONSE_RESULT_SET_PAYLOAD
DVLOG_LP(log_trace) << (payload.length() > 0 ? "<-- RESPONSE_RESULT_SET_PAYLOAD " : "<-- RESPONSE_RESULT_SET_COMMIT ") << static_cast<std::uint32_t>(slot) << ", " << static_cast<std::uint32_t>(writer);
std::unique_lock<std::mutex> lock(mutex_);
Expand Down Expand Up @@ -281,9 +291,7 @@ class stream_socket
do {std::unique_lock<std::mutex> lock(mutex_);
session_closed_ = true;
} while (false);
DVLOG_LP(log_trace) << "<-- RESPONSE_SESSION_BYE_OK ";
send_response(RESPONSE_SESSION_BYE_OK, 0, "", true);
continue;
return await_result::termination_request;
}
DVLOG_LP(log_trace) << "socket is closed by the client abnormally";
return await_result::socket_closed;
Expand Down

0 comments on commit f7c1a0b

Please sign in to comment.