Skip to content

Commit

Permalink
🐛 Fix remote logger handler cleanup
Browse files Browse the repository at this point in the history
While the code works, the handers were defined in a way in which they would never be cleaned up. Not
a problem in practice as these handlers will get garbage collected, but it's better to make this
code more accurate.
  • Loading branch information
wwilsman committed Mar 19, 2021
1 parent 6fc731e commit 843dc1a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/logger/src/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,21 @@ export default class PercyLogger {
// if not already connected, wait until the timeout
if (!this.isRemote) {
err = await new Promise(resolve => {
let done = error => {
let done = event => {
socket.removeEventListener('error', done);
socket.removeEventListener('open', done);
clearTimeout(timeoutid);
resolve(error);

resolve(event?.error || (event?.type === 'error' && (
'Error: Socket connection failed')));
};

let timeoutid = setTimeout(done, timeout, (
'Error: Socket connection timed out'));
let timeoutid = setTimeout(done, timeout, {
error: 'Error: Socket connection timed out'
});

socket.addEventListener('open', () => done());
socket.addEventListener('error', ({ error }) => done(error));
socket.addEventListener('open', done);
socket.addEventListener('error', done);
});
}

Expand Down

0 comments on commit 843dc1a

Please sign in to comment.