From dfae87f325337bed0fe0ca96e5c2b08334f65bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Sun, 6 Nov 2022 00:13:40 +0100 Subject: [PATCH 1/4] Transport: Handle keep alive request from server Closes #754. --- lib/Transport.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Transport.js b/lib/Transport.js index 33018e7..f5016e1 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -340,7 +340,18 @@ module.exports = class Transport _onData(data) { - // CRLF Keep Alive response from server. Ignore it. + // CRLF Keep Alive request from server, reply. + if (data === '\r\n\r\n') + { + logger.debug('received message with double-CRLF Keep Alive request'); + + // Reply with single CRLF. + this.socket.send('\r\n'); + + return; + } + + // CRLF Keep Alive response from server, ignore it. if (data === '\r\n') { logger.debug('received message with CRLF Keep Alive response'); From f98bfb2d73d603a7e4f7d52bf16fb7da09769aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Sun, 6 Nov 2022 00:17:21 +0100 Subject: [PATCH 2/4] Update CHANGELOG --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9818cc7..db042c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +### NEXT RELEASE + +* Transport: Handle keep alive request from server (#791). + + ### 3.10.0 * Fix typescript typings (#648). From bc5e9807b41baea27ea533f59c207ffa0150b831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 7 Nov 2022 13:35:58 +0100 Subject: [PATCH 3/4] catch socket send error --- lib/Transport.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Transport.js b/lib/Transport.js index f5016e1..d2792cc 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -345,8 +345,14 @@ module.exports = class Transport { logger.debug('received message with double-CRLF Keep Alive request'); - // Reply with single CRLF. - this.socket.send('\r\n'); + try + { + // Reply with single CRLF. + this.socket.send('\r\n'); + } catch (error) + { + logger.warn(`error sending Keep Alive response: ${error}`); + } return; } From 6c459c446c1da06048201b77bb0bc6473e6a552d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 7 Nov 2022 13:42:10 +0100 Subject: [PATCH 4/4] lint --- lib/Transport.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Transport.js b/lib/Transport.js index d2792cc..52c6f15 100644 --- a/lib/Transport.js +++ b/lib/Transport.js @@ -349,7 +349,8 @@ module.exports = class Transport { // Reply with single CRLF. this.socket.send('\r\n'); - } catch (error) + } + catch (error) { logger.warn(`error sending Keep Alive response: ${error}`); }