Skip to content

Commit

Permalink
proto_*: move TCP request in shm, not pkg
Browse files Browse the repository at this point in the history
This is because TCP connection might get re-balanced on different nodes

Thanks go to ConnexCS for reporting this!

(cherry picked from commit c49ba70)
  • Loading branch information
razvancrainea committed Jul 31, 2023
1 parent 050db88 commit c117f2e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions modules/proto_bin/bin_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ static inline int bin_handle_req(struct tcp_req *req,
if (!size && req != &_bin_common_current_req) {
/* if we no longer need this tcp_req
* we can free it now */
pkg_free(req);
shm_free(req);
con->con_req = NULL;
}

con->msg_attempts = 0;
Expand Down Expand Up @@ -121,7 +122,7 @@ static inline int bin_handle_req(struct tcp_req *req,
/* let's duplicate this - most likely another conn will come in */

LM_DBG("We didn't manage to read a full request\n");
con->con_req = pkg_malloc(sizeof(struct tcp_req));
con->con_req = shm_malloc(sizeof(struct tcp_req));
if (con->con_req == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
goto error;
Expand Down
5 changes: 3 additions & 2 deletions modules/proto_hep/proto_hep.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ static inline int hep_handle_req(struct tcp_req *req,
if (!size && req != &hep_current_req) {
/* if we no longer need this tcp_req
* we can free it now */
pkg_free(req);
shm_free(req);
con->con_req = NULL;
}

con->msg_attempts = 0;
Expand Down Expand Up @@ -681,7 +682,7 @@ static inline int hep_handle_req(struct tcp_req *req,
/* let's duplicate this - most likely another conn will come in */

LM_DBG("We didn't manage to read a full request\n");
con->con_req = pkg_malloc(sizeof(struct tcp_req));
con->con_req = shm_malloc(sizeof(struct tcp_req));
if (con->con_req == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
goto error;
Expand Down
4 changes: 2 additions & 2 deletions modules/proto_msrp/msrp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static int msrp_handle_req(struct msrp_req *req,
if (req != &msrp_current_req) {
/* if we no longer need this tcp_req
* we can free it now */
pkg_free(req);
shm_free(req);
con->con_req = NULL;
}
} else {
Expand All @@ -375,7 +375,7 @@ static int msrp_handle_req(struct msrp_req *req,
/* let's duplicate this - most likely another conn will come in */

LM_DBG("We didn't manage to read a full request\n");
con_req = pkg_malloc(sizeof(struct msrp_req));
con_req = shm_malloc(sizeof(struct msrp_req));
if (con_req == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
goto error;
Expand Down
5 changes: 3 additions & 2 deletions modules/proto_smpp/proto_smpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ static int smpp_handle_req(struct tcp_req *req, struct tcp_connection *con)
if (!size && req != &smpp_current_req) {
/* if we no longer need this tcp_req
* we can free it now */
pkg_free(req);
shm_free(req);
con->con_req = NULL;
}

con->msg_attempts = 0;
Expand Down Expand Up @@ -307,7 +308,7 @@ static int smpp_handle_req(struct tcp_req *req, struct tcp_connection *con)
/* let's duplicate this - most likely another conn will come in */

LM_DBG("We didn't manage to read a full request\n");
con->con_req = pkg_malloc(sizeof(struct tcp_req));
con->con_req = shm_malloc(sizeof(struct tcp_req));
if (con->con_req == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
return -1;
Expand Down
4 changes: 2 additions & 2 deletions modules/proto_ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ static int ws_process(struct tcp_connection *con)
if (req != &_ws_common_current_req) {
/* make sure we cleanup the request in the connection */
con->con_req = NULL;
pkg_free(req);
shm_free(req);
}

} else {
Expand All @@ -573,7 +573,7 @@ static int ws_process(struct tcp_connection *con)
/* let's duplicate this - most likely another conn will come in */

LM_DBG("We didn't manage to read a full request\n");
newreq = pkg_malloc(sizeof(struct ws_req));
newreq = shm_malloc(sizeof(struct ws_req));
if (newreq == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
goto error;
Expand Down
10 changes: 6 additions & 4 deletions modules/proto_ws/ws_handshake_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ static int ws_server_handshake(struct tcp_connection *con)
}

con->msg_attempts = 0;
if (req != &_ws_common_tcp_current_req)
pkg_free(req);
if (req != &_ws_common_tcp_current_req) {
shm_free(req);
con->con_req = NULL;
}

/* handshake now completed, destroy the handshake data */
WS_STATE(con) = WS_CON_HANDSHAKE_DONE;
Expand All @@ -549,7 +551,7 @@ static int ws_server_handshake(struct tcp_connection *con)
if (!req->complete && (req == &_ws_common_tcp_current_req)) {
/* let's duplicate this - most likely another conn will come in */

con->con_req = pkg_malloc(sizeof(struct tcp_req));
con->con_req = shm_malloc(sizeof(struct tcp_req));
if (con->con_req == NULL) {
LM_ERR("No more mem for dynamic con request buffer\n");
goto error;
Expand Down Expand Up @@ -596,7 +598,7 @@ static int ws_server_handshake(struct tcp_connection *con)
if (WS_STATE(con) == WS_CON_BAD_REQ)
ws_bad_handshake(con);
if (req != &_ws_common_tcp_current_req) {
pkg_free(req);
shm_free(req);
con->con_req = NULL;
}
return -1;
Expand Down

0 comments on commit c117f2e

Please sign in to comment.