Skip to content

Commit

Permalink
CHANGE removed separate long request timeout
Browse files Browse the repository at this point in the history
Unified with standard request timeout.
Refs #1099
  • Loading branch information
michalvasko committed Apr 24, 2018
1 parent 7690a27 commit 9562dd4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 46 deletions.
23 changes: 2 additions & 21 deletions CMakeLists.txt
Expand Up @@ -176,27 +176,8 @@ set(STORE_CONFIG_CHANGE_NOTIF 1 CACHE BOOL
"Save config-change notifications (RFC 6470) in the notification store (slows down the commit process).")

# timeouts
if(REQUEST_TIMEOUT EQUAL "0" OR LONG_REQUEST_TIMEOUT EQUAL "0")
message(STATUS "Sysrepo API request Timeouts (REQUEST_TIMEOUT/LONG_REQUEST_TIMEOUT) have been disabled.")
set(REQUEST_TIMEOUT 0 CACHE INTEGER
"Timeout (in seconds) for standard Sysrepo API requests. Set to 0 for no timeout.")
set(LONG_REQUEST_TIMEOUT 0 CACHE INTEGER
"Timeout (in seconds) for Sysrepo API requests that can take longer than standard requests (commit, copy-config, rpc, action). Set to 0 for no timeout.")
endif(REQUEST_TIMEOUT EQUAL "0" OR LONG_REQUEST_TIMEOUT EQUAL "0")

if(NOT DEFINED REQUEST_TIMEOUT)
set(REQUEST_TIMEOUT 4 CACHE INTEGER
"Timeout (in seconds) for standard Sysrepo API requests. Set to 0 for no timeout.")
endif(NOT DEFINED REQUEST_TIMEOUT)

if(NOT DEFINED LONG_REQUEST_TIMEOUT)
set(LONG_REQUEST_TIMEOUT 15 CACHE INTEGER
"Timeout (in seconds) for Sysrepo API requests that can take longer than standard requests (commit, copy-config, rpc, action). Set to 0 for no timeout.")
endif(NOT DEFINED LONG_REQUEST_TIMEOUT)

if(REQUEST_TIMEOUT GREATER LONG_REQUEST_TIMEOUT)
message(FATAL_ERROR "LONG_REQUEST_TIMEOUT (${LONG_REQUEST_TIMEOUT}) must be greater than REQUEST_TIMEOUT (${REQUEST_TIMEOUT})")
endif(REQUEST_TIMEOUT GREATER LONG_REQUEST_TIMEOUT)
set(REQUEST_TIMEOUT 15 CACHE INTEGER
"Timeout (in seconds) for Sysrepo API requests. Set to 0 for no timeout.")

set(COMMIT_VERIFY_TIMEOUT 10 CACHE INTEGER
"Timeout (in seconds) that a commit request can wait for answer from commit verifiers and change notification subscribers.")
Expand Down
1 change: 0 additions & 1 deletion INSTALL.md
Expand Up @@ -165,7 +165,6 @@ There are several timeouts that can be configured via CMake variables:
CMake variable | Default value | Description
--------------------------- | ------------- | -----------
`REQUEST_TIMEOUT` | 3 sec | Timeout (in seconds) for standard Sysrepo API requests. Set to 0 to disable request timeouts.
`LONG_REQUEST_TIMEOUT` | 15 sec | Timeout (in seconds) for Sysrepo API requests that can take longer than standard requests (commit, copy-config, rpc, action). Set to 0 to disable timeouts.
`COMMIT_VERIFY_TIMEOUT` | 10 sec | Timeout (in seconds) that a commit request can wait for answer from commit verifiers and change notification subscribers.
`OPER_DATA_PROVIDE_TIMEOUT` | 2 sec | Timeout (in seconds) that a request can wait for operational data from data providers.
`NOTIF_AGE_TIMEOUT` | 60 min | Timeout (in minutes) after which stored notifications will be aged out and erased from notification store.
Expand Down
25 changes: 1 addition & 24 deletions src/clientlib/cl_common.c
Expand Up @@ -395,7 +395,7 @@ cl_socket_connect(sr_conn_ctx_t *conn_ctx, const char *socket_path)
}

/* set timeout for receive operation */
if(SR_REQUEST_TIMEOUT > 0) {
if (SR_REQUEST_TIMEOUT > 0) {
tv.tv_sec = SR_REQUEST_TIMEOUT;
tv.tv_usec = 0;
rc = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
Expand Down Expand Up @@ -487,24 +487,12 @@ cl_request_process(sr_session_ctx_t *session, Sr__Msg *msg_req, Sr__Msg **msg_re
sr_mem_ctx_t *sr_mem_resp, const Sr__Operation expected_response_op)
{
int rc = SR_ERR_OK;
struct timeval tv = { 0, };

CHECK_NULL_ARG4(session, session->conn_ctx, msg_req, msg_resp);

SR_LOG_DBG("Sending %s request.", sr_gpb_operation_name(expected_response_op));

pthread_mutex_lock(&session->conn_ctx->lock);
/* some operation may take more time, raise the timeout */
if ((SR__OPERATION__COMMIT == expected_response_op || SR__OPERATION__COPY_CONFIG == expected_response_op ||
SR__OPERATION__RPC == expected_response_op || SR__OPERATION__ACTION == expected_response_op) &&
SR_LONG_REQUEST_TIMEOUT > 0) {
tv.tv_sec = SR_LONG_REQUEST_TIMEOUT;
tv.tv_usec = 0;
rc = setsockopt(session->conn_ctx->fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
if (-1 == rc) {
SR_LOG_WRN("Unable to set timeout for socket operations: %s", sr_strerror_safe(errno));
}
}

/* send the request */
rc = cl_message_send(session->conn_ctx, msg_req);
Expand All @@ -526,17 +514,6 @@ cl_request_process(sr_session_ctx_t *session, Sr__Msg *msg_req, Sr__Msg **msg_re
return rc;
}

/* change socket timeout to the standard value */
if ((SR__OPERATION__COMMIT == expected_response_op || SR__OPERATION__COPY_CONFIG == expected_response_op ||
SR__OPERATION__RPC == expected_response_op || SR__OPERATION__ACTION == expected_response_op) &&
SR_LONG_REQUEST_TIMEOUT > 0) {
tv.tv_sec = SR_REQUEST_TIMEOUT;
rc = setsockopt(session->conn_ctx->fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv));
if (-1 == rc) {
SR_LOG_WRN("Unable to set timeout for socket operations: %s", sr_strerror_safe(errno));
}
}

pthread_mutex_unlock(&session->conn_ctx->lock);

SR_LOG_DBG("%s response received, processing.", sr_gpb_operation_name(expected_response_op));
Expand Down

0 comments on commit 9562dd4

Please sign in to comment.