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

Commit

Permalink
Elaborate on async stack trace warning (#340)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gaofanmichael authored Oct 20, 2017
1 parent 82fb478 commit 964cc31
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/agent/debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as _ from 'lodash';
import * as path from 'path';
import * as semver from 'semver';
import * as util from 'util';
import * as utils from './util/utils';
import * as http from 'http';

import {Controller} from './controller';
Expand Down Expand Up @@ -206,6 +207,13 @@ export class Debuglet extends EventEmitter {
*/
async start(): Promise<void> {
const that = this;
process.on('warning', (warning) => {
if ((warning as any).code ===
'INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE') {
that.logger_.info(utils.messages.ASYNC_TRACES_WARNING);
}
});

const stat = promisify(fs.stat);

try {
Expand Down
6 changes: 5 additions & 1 deletion src/agent/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const messages = {
CAPTURE_BREAKPOINT_DATA: 'Error trying to capture snapshot data: ',
INVALID_LINE_NUMBER: 'Invalid snapshot position: ',
COULD_NOT_FIND_OUTPUT_FILE:
'Could not determine the output file associated with the transpiled input file'
'Could not determine the output file associated with the transpiled input file',
ASYNC_TRACES_WARNING:
'The Stackdriver Debugger for Node.js does not require V8 Inspector ' +
'async stack traces. The INSPECTOR_ASYNC_STACK_TRACES_NOT_AVAILABLE ' +
'can be ignored.'
};

export interface Listener {
Expand Down
45 changes: 42 additions & 3 deletions test/test-debuglet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as stackdriver from '../src/types/stackdriver';
import {DebugAgentConfig} from '../src/agent/config';
import {Debuggee} from '../src/debuggee';
import * as semver from 'semver';

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

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

describe('setup', function() {
before(function() { oldGP = process.env.GCLOUD_PROJECT; });
before(function() {
oldGP = process.env.GCLOUD_PROJECT;
});

after(function() { process.env.GCLOUD_PROJECT = oldGP; });

beforeEach(function() {
delete process.env.GCLOUD_PROJECT;
nocks.oauth2();
});

afterEach(function() { nock.cleanAll(); });
afterEach(function() {
nock.cleanAll();
});

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

it('should elaborate on inspector warning on 32 bit but not on 64 bit',
function(done) {
const projectId = '11020304f2934-a';
const debug = new Debug(
{projectId: projectId, credentials: fakeCredentials});
const debuglet = new Debuglet(debug, defaultConfig);
let logText = '';
debuglet.logger_.info = function(s: string) {
logText += s;
};
nocks.projectId('project-via-metadata');
const scope = nock(API)
.post(REGISTER_PATH)
.reply(200, {debuggee: {id: DEBUGGEE_ID}});

debuglet.once('registered', function(id: string) {
assert.equal(id, DEBUGGEE_ID);
// TODO: Handle the case where debuglet.debuggee is undefined
assert.equal((debuglet.debuggee_ as Debuggee).project, projectId);
const arch = process.arch;
if (semver.satisfies(process.version, '>=8.5') &&
(arch === 'ia32' || arch === 'x86')) {
assert(logText.includes(utils.messages.ASYNC_TRACES_WARNING));
} else {
assert(!logText.includes(utils.messages.ASYNC_TRACES_WARNING));
}
debuglet.stop();
scope.done();
done();
});

debuglet.start();
});

it('should not start when projectId is not available', function(done) {
const savedGetProjectId = Debuglet.getProjectId;
Debuglet.getProjectId = () => {
Expand Down

0 comments on commit 964cc31

Please sign in to comment.