Skip to content

Commit

Permalink
Adding TCP send retries (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
epacke authored Nov 19, 2024
1 parent 058ef4b commit 02fd188
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pipeline-ui/backend/src/api/v1/sendLogLines/sendTCPString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,30 @@
import net from 'net';
import {LOGSTASH} from '../../../constants/LogstashAddress';
import logger from '../../../util/Logger';
import config from '../../../constants/config';

function sendTCP(payload: string, port: number) {
const conn = net.createConnection({host: LOGSTASH, port: port}, function () {
function sendTCP(payload: string, port: number, retries = 0) {
const conn = net.createConnection({host: LOGSTASH, port: port}, function() {
conn.write(payload);
}).on('error', function (err) {
}).on('error', function(err) {
logger.error({
message: `Failed to send payload to ${port}.` +
`Has all logstash pipelines started successfully?`,
payload,
details: err.message,
});
setTimeout(() => {
if (retries > config.maxRetries) {
logger.error({
message: `Gave up sending payload to ${port}. Timeout reached.`,
payload,
details: err.message,
});
return;
}
logger.info(`Retrying sending payload to port ${port}`);
sendTCP(payload, port, ++retries);
}, config.retryWaitTimeSeconds * 1000);
});
}

Expand Down
4 changes: 4 additions & 0 deletions pipeline-ui/backend/src/constants/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
maxRetries: 5,
retryWaitTimeSeconds: 1,
};

0 comments on commit 02fd188

Please sign in to comment.