I have a simple jest test code that creates an instance of a new winston logger using the following transport configuration:
it("using TCP protocol", async (done) => {
const sys: any = new ws.Syslog({
host: "localhost",
port: 514,
protocol: "tcp4",
path: "/dev/log",
app_name: "ESB",
facility: "local5",
eol: "\n",
});
let syslogger = winston.createLogger({
levels: winston.config.syslog.levels,
transports: [
sys
]
});
syslogger.info("test msg");
syslogger.close();
});
The test runs fine and I can see that the messages being received by syslog but the test does not seem to return and hangs after showing the test outcome. On debugging (winston-syslog.js) I see that it is trying to connect again. The event handler doesn't seem to exit. Is this intended or could this be a bug?
.on('close', () => {
//
// Attempt to reconnect on lost connection(s), progressively
// increasing the amount of time between each try.
//
const interval = Math.pow(2, this.retries);
this.connected = false;
setTimeout(() => {
this.retries++;
**this.socket.connect(this.port, this.host);**
}, interval * 1000);
})
I understand that the line exists for attempting to reconnect on lost connections. But how do I go about actually closing the connection assuming one was created successfully, messages sent, and I no longer need the connection? If that line is commented, jest returns as expected.
The code is run on Centos 7 with node v 12.13.0 and:
"winston": "^3.2.1",
"winston-syslog": "^2.4.0",
"winston-transport": "^4.3.0"
Am I missing any configuration or clean up calls? Is there a way I can make the close() event handler exit?
Thanks!