Skip to content

Commit

Permalink
* (Apollon77) Ignore errors from forked process after response was se…
Browse files Browse the repository at this point in the history
…nt for GetHistory
  • Loading branch information
Apollon77 committed Jun 24, 2022
1 parent a74fd1a commit b2d7797
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ This adapter saves state history in a two-staged process.
-->

## Changelog

### __WORK IN PROGRESS__
* (Apollon77) Ignore errors from forked process after response was sent for GetHistory

### 2.1.4 (2022-06-12)
* (Apollon77) Make sure debug log is active according to the settings

Expand Down
16 changes: 10 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ function getHistory(msg) {
} else {
// to use parallel requests activate this.
if (1 || typeof GetHistory === 'undefined') {
let responseSent = false;
adapter.log.debug(`${options.logId} use parallel requests for getHistory`);
try {
let gh = cp.fork(__dirname + '/lib/getHistory.js', [JSON.stringify(options)], {silent: false});
Expand All @@ -1328,12 +1329,13 @@ function getHistory(msg) {

gh.on('error', err => {
gh = null;
adapter.log.info(`${options.logId} Error communicating to forked process: ${err.message}`);
adapter.sendTo(msg.from, msg.command, {
!responseSent && adapter.log.info(`${options.logId} Error communicating to forked process: ${err.message}`);
!responseSent && adapter.sendTo(msg.from, msg.command, {
result: [],
step: null,
error: null
}, msg.callback);
responseSent = true;
});

gh.on('message', data => {
Expand Down Expand Up @@ -1362,20 +1364,22 @@ function getHistory(msg) {
const overallLength = data[2];
const step = data[3];
if (options.result) {
adapter.log.debug(`${options.logId} Send: ${options.result.length} of: ${overallLength} in: ${Date.now() - startTime}ms`);
adapter.sendTo(msg.from, msg.command, {
!responseSent && adapter.log.debug(`${options.logId} Send: ${options.result.length} of: ${overallLength} in: ${Date.now() - startTime}ms`);
!responseSent && adapter.sendTo(msg.from, msg.command, {
result: options.result,
step: step,
error: null
}, msg.callback);
responseSent = true;
options.result = null;
} else {
adapter.log.info(`${options.logId} No Data`);
adapter.sendTo(msg.from, msg.command, {
!responseSent && adapter.log.info(`${options.logId} No Data`);
!responseSent && adapter.sendTo(msg.from, msg.command, {
result: [],
step: null,
error: null
}, msg.callback);
responseSent = true;
}
} else if (cmd === 'debug') {
let line = data.slice(1).join(', ');
Expand Down

0 comments on commit b2d7797

Please sign in to comment.