Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit 964cc31

Browse files
Elaborate on async stack trace warning (#340)
Since async_stack_traces is disabled on 32 bit platform, a warning message was emitted from node runtime. This PR elaborates the reason for the warning and lets user to ignore the warning.
1 parent 82fb478 commit 964cc31

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/agent/debuglet.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import * as _ from 'lodash';
3030
import * as path from 'path';
3131
import * as semver from 'semver';
3232
import * as util from 'util';
33+
import * as utils from './util/utils';
3334
import * as http from 'http';
3435

3536
import {Controller} from './controller';
@@ -206,6 +207,13 @@ export class Debuglet extends EventEmitter {
206207
*/
207208
async start(): Promise<void> {
208209
const that = this;
210+
process.on('warning', (warning) => {
211+
if ((warning as any).code ===
212+
'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') {
213+
that.logger_.info(utils.messages.ASYNC_TRACES_WARNING);
214+
}
215+
});
216+
209217
const stat = promisify(fs.stat);
210218

211219
try {

src/agent/util/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export const messages = {
2424
CAPTURE_BREAKPOINT_DATA: 'Error trying to capture snapshot data: ',
2525
INVALID_LINE_NUMBER: 'Invalid snapshot position: ',
2626
COULD_NOT_FIND_OUTPUT_FILE:
27-
'Could not determine the output file associated with the transpiled input file'
27+
'Could not determine the output file associated with the transpiled input file',
28+
ASYNC_TRACES_WARNING:
29+
'The Stackdriver Debugger for Node.js does not require V8 Inspector ' +
30+
'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' +
31+
'can be ignored.'
2832
};
2933

3034
export interface Listener {

test/test-debuglet.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import * as stackdriver from '../src/types/stackdriver';
1818
import {DebugAgentConfig} from '../src/agent/config';
1919
import {Debuggee} from '../src/debuggee';
20+
import * as semver from 'semver';
2021

2122
import * as _ from 'lodash';
2223
import * as path from 'path';
@@ -29,6 +30,7 @@ import * as dns from 'dns';
2930
import * as extend from 'extend';
3031
const metadata: {project: any, instance: any} = require('gcp-metadata');
3132
import {Debug} from '../src/client/stackdriver/debug';
33+
import * as utils from '../src/agent/util/utils'
3234

3335
const DEBUGGEE_ID = 'bar';
3436
const API = 'https://clouddebugger.googleapis.com';
@@ -289,16 +291,19 @@ describe('Debuglet', function() {
289291
});
290292

291293
describe('setup', function() {
292-
before(function() { oldGP = process.env.GCLOUD_PROJECT; });
294+
before(function() {
295+
oldGP = process.env.GCLOUD_PROJECT;
296+
});
293297

294298
after(function() { process.env.GCLOUD_PROJECT = oldGP; });
295-
296299
beforeEach(function() {
297300
delete process.env.GCLOUD_PROJECT;
298301
nocks.oauth2();
299302
});
300303

301-
afterEach(function() { nock.cleanAll(); });
304+
afterEach(function() {
305+
nock.cleanAll();
306+
});
302307

303308
it('should merge config correctly', function() {
304309
const testValue = 2 * defaultConfig.capture.maxExpandFrames;
@@ -315,6 +320,40 @@ describe('Debuglet', function() {
315320
assert.deepEqual(mergedConfig, compareConfig);
316321
});
317322

323+
it('should elaborate on inspector warning on 32 bit but not on 64 bit',
324+
function(done) {
325+
const projectId = '11020304f2934-a';
326+
const debug = new Debug(
327+
{projectId: projectId, credentials: fakeCredentials});
328+
const debuglet = new Debuglet(debug, defaultConfig);
329+
let logText = '';
330+
debuglet.logger_.info = function(s: string) {
331+
logText += s;
332+
};
333+
nocks.projectId('project-via-metadata');
334+
const scope = nock(API)
335+
.post(REGISTER_PATH)
336+
.reply(200, {debuggee: {id: DEBUGGEE_ID}});
337+
338+
debuglet.once('registered', function(id: string) {
339+
assert.equal(id, DEBUGGEE_ID);
340+
// TODO: Handle the case where debuglet.debuggee is undefined
341+
assert.equal((debuglet.debuggee_ as Debuggee).project, projectId);
342+
const arch = process.arch;
343+
if (semver.satisfies(process.version, '>=8.5') &&
344+
(arch === 'ia32' || arch === 'x86')) {
345+
assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING));
346+
} else {
347+
assert(!logText.includes(utils.messages.ASYNC_TRACES_WARNING));
348+
}
349+
debuglet.stop();
350+
scope.done();
351+
done();
352+
});
353+
354+
debuglet.start();
355+
});
356+
318357
it('should not start when projectId is not available', function(done) {
319358
const savedGetProjectId = Debuglet.getProjectId;
320359
Debuglet.getProjectId = () => {

0 commit comments

Comments
 (0)