Skip to content

Commit 8a8bf8b

Browse files
Merge pull request #24 from datatraders/master
fix onError - fix to prevent errors because of too much recursion
2 parents 5b96ab4 + 82ba7a1 commit 8a8bf8b

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

index.js

100644100755
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ function zongjiManager(dsn, options, onBinlog) {
77
var newInst = new ZongJi(dsn, options);
88
newInst.on('error', function(reason) {
99
newInst.removeListener('binlog', onBinlog);
10-
setTimeout(function() {
11-
// If multiple errors happened, a new instance may have already been created
12-
if(!('child' in newInst)) {
13-
newInst.child = zongjiManager(dsn, Object.assign({}, options, newInst.binlogNextPos
14-
? { binlogName: newInst.binlogName,
10+
newInst.child = false;
11+
setTimeout(function() {
12+
// If multiple errors happened, a new instance may have already been created
13+
if(!newInst.child) {
14+
var newInstNext = zongjiManager(dsn, Object.assign({}, options, newInst.binlogNextPos
15+
? { binlogName: newInst.binlogName,
1516
binlogNextPos: newInst.binlogNextPos
16-
}
17-
: {}
18-
), onBinlog);
19-
newInst.emit('child', newInst.child, reason);
20-
newInst.child.on('child', child => newInst.emit('child', child));
21-
}
22-
}, RETRY_TIMEOUT);
17+
}
18+
: {}
19+
), onBinlog);
20+
newInst.stop();
21+
newInst = newInstNext;
22+
newInst.child = true;
23+
}
24+
}, RETRY_TIMEOUT);
2325
});
2426
newInst.on('binlog', onBinlog);
2527
newInst.start(options);

0 commit comments

Comments
 (0)