When I enable SIP.js keep-alive, it sends double CR-LFs to Kamailio via websocket, however Kamailio understands it as a malformed SIP message, and therefore does not reply with a single CR-LF.
Debug log from websocket module upon arrival of keep-alive:
`15(88) DEBUG: websocket [ws_frame.c:415]: decode_and_validate_ws_frame(): decoding WebSocket frame` `15(88) DEBUG: websocket [ws_frame.c:451]: decode_and_validate_ws_frame(): supported non-control frame: 0x1` `15(88) DEBUG: websocket [ws_frame.c:550]: decode_and_validate_ws_frame(): Rx (decoded):` ` ` `15(88) DEBUG: websocket [ws_frame.c:684]: ws_frame_receive(): Rx SIP message:` ` ` ` ` `15(88) DEBUG: websocket [ws_conn.c:383]: wsconn_put(): wsconn_put start for [0x7fc8cbd45860] refcnt [2]` `15(88) DEBUG: websocket [ws_conn.c:416]: wsconn_put(): wsconn_put end for [0x7fc8cbd45860] refcnt [1]` `15(88) INFO: <core> [parser/parse_fline.c:87]: parse_first_line(): ERROR: parse_first_line: message too short: 0` `15(88) ERROR: <core> [parser/parse_fline.c:257]: parse_first_line(): parse_first_line: bad message (offset: 0)` `15(88) ERROR: <core> [parser/msg_parser.c:671]: parse_msg(): ERROR: parse_msg: message=<` ` ` `>` `15(88) ERROR: <core> [receive.c:173]: receive_msg(): core parsing of SIP message failed (10.0.1.73:1043/6)`
Just as a reference: This is the way SIP outbound handles keepalives for connection-oriented protocols - RFC 5626 section 3.5.1.
Are you using the outbound module at all?
@afr1983 - can you try with patch 585c60f (or master branch) and see if all ok? If yes, I will backport to 4.4.
@oej Not using the outbound module, maybe I should, I will check it out.
@miconda Thanks, I was preparing a patch myself, but thankfully you were quicker as yours seems more elegant (and I learned a couple things from yours). I will test it ASAP and inform you of the result.
@miconda Okay there is one issue in that patch, it is that the server is checking only for a single CRLF incoming, while it should check for double. I've changed it to
``` if(frame.payload_len==CRLF_LEN*2 && strncmp(frame.payload_data, "\r\n\r\n", CRLF_LEN*2)==0) ```
And it works with SIP.js now.
Added also the handling of 2xCRLF as you pointed. I left the single CRLF just in case. It will be backported.
Closed #810.