Skip to content

Commit

Permalink
test debug
Browse files Browse the repository at this point in the history
  • Loading branch information
avtolstoy committed Feb 15, 2024
1 parent 4ec1a35 commit 022c82c
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ class Device extends EventEmitter {
} else {
break;
}
if (mboxMessages.length > 1000) {
this._log.error('mbox over 1000 messages !?');
break;
}
} catch (err) {
break;
}
Expand Down Expand Up @@ -480,18 +484,34 @@ class Device extends EventEmitter {
}

async _close() {
let timeoutAt = Date.now() + DEVICE_OPEN_TIMEOUT;

Check failure on line 487 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'timeoutAt' is never reassigned. Use 'const' instead

Check failure on line 487 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'timeoutAt' is never reassigned. Use 'const' instead

Check failure on line 487 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'timeoutAt' is never reassigned. Use 'const' instead
const canClose = () => (!this._opening && !this._closing);
while (!canClose()) {
const p = new Promise(resolve => {
let timer = null;
const onChange = () => {
if (canClose()) {
this.off('_opening', onChange);
this.off('_closing', onChange);
resolve();
}
};
const onTimeout = async () => {
this._log.error('Timeout while _closing_ the device, attempt to force close');
this.off('_opening', onChange);
this.off('_closing', onChange);
if (this._usbDev) {
try {
await this._usbDev.close({ processPendingRequests: false });
} catch (e) {
this._log.error('Failed to force-close the device', e);
}
}
reject(new Error('Timeout while _closing_ the device'));

Check failure on line 510 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'reject' is not defined

Check failure on line 510 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'reject' is not defined

Check failure on line 510 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'reject' is not defined
};
this.on('_opening', onChange);
this.on('_closing', onChange);
timer = setTimeout(onTimeout, Math.max(0, timeoutAt - Date.now()));

Check failure on line 514 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'timer' is assigned a value but never used

Check failure on line 514 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'timer' is assigned a value but never used

Check failure on line 514 in lib/device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'timer' is assigned a value but never used
});
await p;
}
Expand Down
60 changes: 60 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,68 @@ const { Logger } = require('./logger');
const { RunMode, initConfig, showUsage, config } = require('./config');
const { isInternalError } = require('./error');
const { version: PACKAGE_VERSION } = require('../package.json');
const async_hooks = require('async_hooks');

Check failure on line 8 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Identifier 'async_hooks' is not in camel case

Check failure on line 8 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Identifier 'async_hooks' is not in camel case

Check failure on line 8 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Identifier 'async_hooks' is not in camel case

let hook = null;
let hookMap = new Map();

Check failure on line 11 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'hookMap' is never reassigned. Use 'const' instead

Check failure on line 11 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'hookMap' is never reassigned. Use 'const' instead

Check failure on line 11 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'hookMap' is never reassigned. Use 'const' instead

async function run() {
hook = async_hooks.createHook({

Check failure on line 14 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Identifier 'async_hooks' is not in camel case

Check failure on line 14 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Identifier 'async_hooks' is not in camel case

Check failure on line 14 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Identifier 'async_hooks' is not in camel case
init: (asyncId, type, triggerAsyncId, resource) => {
if (resource && resource._timerArgs && resource._timerArgs[0] == 'notrack') {

Check failure on line 16 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Expected '===' and instead saw '=='

Check failure on line 16 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Expected '===' and instead saw '=='

Check failure on line 16 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Expected '===' and instead saw '=='
return;
}
const error = {};
Error.captureStackTrace(error);
const stack = error.stack.split("\n").map(line => line.trim()).slice(1);

Check failure on line 21 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Strings must use singlequote

Check failure on line 21 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Strings must use singlequote

Check failure on line 21 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Strings must use singlequote
hookMap.set(asyncId, {
type,
triggerAsyncId,
resource,
stack,
count: 0,
timer: type == 'PROMISE' ? setInterval(() => {

Check failure on line 28 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

Expected '===' and instead saw '=='

Check failure on line 28 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

Expected '===' and instead saw '=='

Check failure on line 28 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

Expected '===' and instead saw '=='
console.log('================================================================');
const m = hookMap.get(asyncId);
m.count++;
console.log(`async op=${asyncId} stalled for over ${10 * m.count} mins`);
console.log(type);
console.log(resource);
console.log('stack:');
console.log(stack);
let parentId = triggerAsyncId;
while (parentId) {
const parent = hookMap.get(parentId);
if (!parent) {
break;
}
parentId = parent.triggerAsyncId;
console.log(`Parent ${parentId}`);
console.log(type);
console.log(resource);
console.log('stack:');
console.log(parent.stack);
}
console.log('done=============================================================\r\n\r\n');
}, 10 * 60 * 1000, 'notrack') : null
});
},
destroy: (asyncId) => {
const task = hookMap.get(asyncId);
if (task && task.timer) {
clearInterval(task.timer);
}
hookMap.delete(asyncId);
},
promiseResolve: (asyncId) => {
const task = hookMap.get(asyncId);
if (task && task.timer) {
clearInterval(task.timer);
}
hookMap.delete(asyncId);
},
});
hook.enable();
let ok = true;
let runner = null;
try {
Expand Down

0 comments on commit 022c82c

Please sign in to comment.