Module: kamailio
Branch: master
Commit: ef86402d2397ff7b0416bc17ab0a2ba906402215
URL:
https://github.com/kamailio/kamailio/commit/ef86402d2397ff7b0416bc17ab0a2ba…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-10-13T17:33:51+02:00
core: tcp - close connection without data traffic at all
- default timeout: 20sec
- cleanup is done on timer, it can take another 10sec
---
Modified: src/core/tcp_conn.h
Modified: src/core/tcp_main.c
Modified: src/core/tcp_read.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ef86402d2397ff7b0416bc17ab0a2ba…
Patch:
https://github.com/kamailio/kamailio/commit/ef86402d2397ff7b0416bc17ab0a2ba…
---
diff --git a/src/core/tcp_conn.h b/src/core/tcp_conn.h
index 2e58861277c..4cb3da51f40 100644
--- a/src/core/tcp_conn.h
+++ b/src/core/tcp_conn.h
@@ -195,6 +195,8 @@ typedef enum tcp_req_flags
#define TCP_REQ_BCHUNKED(tr) ((tr)->flags & F_TCP_REQ_BCHUNKED)
#endif
+#define KSR_TCP_REQSTATE_DATARECV (1 << 0)
+
typedef struct tcp_req
{
struct tcp_req *next;
@@ -214,6 +216,7 @@ typedef struct tcp_req
int bytes_to_go; /* how many bytes we have still to read from the body*/
enum tcp_req_errors error;
enum tcp_req_states state;
+ unsigned int dxstate;
struct timeval tvrstart;
} tcp_req_t;
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index f4f00c23420..9f39dd72444 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -5454,6 +5454,7 @@ void tcp_timer_check_connections(unsigned int ticks, void *param)
struct timeval tvnow;
long long tvdiff;
long mcmd[2];
+ int cidset = 0;
if(tcp_disable) {
return;
@@ -5466,6 +5467,7 @@ void tcp_timer_check_connections(unsigned int ticks, void *param)
for(i = 0; i < TCP_ID_HASH_SIZE && n < TCPIDLIST_SIZE; i++) {
for(con = tcpconn_id_hash[i]; con && n < TCPIDLIST_SIZE;
con = con->id_next) {
+ cidset = 0;
if(con->state == S_CONN_OK) {
if(con->req.tvrstart.tv_sec > 0) {
tvdiff = 1000000
@@ -5478,18 +5480,34 @@ void tcp_timer_check_connections(unsigned int ticks, void *param)
n, con->id, tvdiff);
tcpidlist[n] = con->id;
n++;
+ cidset = 1;
}
}
}
+ if((cidset == 0)
+ && !(con->req.dxstate & KSR_TCP_REQSTATE_DATARECV)) {
+ if(tvnow.tv_sec - con->timestamp
+ >= KSR_TCP_MSGREAD_TIMEOUT) {
+ LM_DBG("n: %d - connection id: %d (state: %d) - "
+ "message "
+ "receiving timeout: %ld\n",
+ n, con->id, con->state,
+ (long)(tvnow.tv_sec - con->timestamp));
+ tcpidlist[n] = con->id;
+ n++;
+ cidset = 1;
+ }
+ }
}
}
TCPCONN_UNLOCK;
if(n > 0) {
for(i = 0; i < n; i++) {
if((con = tcpconn_get(tcpidlist[i], 0, 0, 0, 0))) {
- LM_CRIT("message reading timeout on connection id: %d - "
+ LM_CRIT("message processing timeout on connection id: %d "
+ "(state: %d) - "
"closing\n",
- tcpidlist[i]);
+ tcpidlist[i], con->state);
mcmd[0] = (long)con;
mcmd[1] = CONN_EOF;
diff --git a/src/core/tcp_read.c b/src/core/tcp_read.c
index 1592936238b..e6e79c2a174 100644
--- a/src/core/tcp_read.c
+++ b/src/core/tcp_read.c
@@ -1580,6 +1580,7 @@ int tcp_read_req(struct tcp_connection *con, int *bytes_read,
}
/* if we are here everything is nice and ok*/
resp = CONN_RELEASE;
+ req->dxstate |= KSR_TCP_REQSTATE_DATARECV;
#ifdef EXTRA_DEBUG
LM_DBG("receiving msg(%p, %d)\n", req->start,
(int)(req->parsed - req->start));