Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

dns: fix "TypeError: Cannot set property 'immediately' of undefined"

Refs #2031.
  • Loading branch information...
commit d9b05336ad887404f541f7006a6a6bb3c4b326ac 1 parent 1001cf4
@koichik authored
Showing with 56 additions and 2 deletions.
  1. +6 −2 lib/dns.js
  2. +50 −0 test/simple/test-dns-error.js
View
8 lib/dns.js
@@ -149,7 +149,9 @@ exports.lookup = function(domain, family, callback) {
wrap.oncomplete = onanswer;
- callback.immediately = true;
+ if (typeof callback === 'function') {
+ callback.immediately = true;
+ }
return wrap;
};
@@ -172,7 +174,9 @@ function resolver(bindingName) {
throw errnoException(errno, bindingName);
}
- callback.immediately = true;
+ if (typeof callback === 'function') {
+ callback.immediately = true;
+ }
return wrap;
}
}
View
50 test/simple/test-dns-error.js
@@ -0,0 +1,50 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+var dns = require('dns');
+var win32 = process.platform === 'win32';
+var errors = 0;
+
+assert.throws(function() {
+ dns.lookup('127.0.0.1');
+}, TypeError, 'undefined is not a function');

Why should this throw?

@koichik Owner
koichik added a note

Sorry, I have a poor memory, I don't remember...
Probably, this test just checked the message string, it did not care about whether an exception should be throws (It is the meaning of "this patch does not fix the main problem").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+if (!win32) {
+ assert.doesNotThrow(function() {
+ dns.lookup('localhost');
+ });
+}
+
+assert.doesNotThrow(function() {
+ dns.resolve('localhost');
+});
+
+process.on('uncaughtException', function(err) {
+ assert.equal(err.message, 'undefined is not a function');
+ ++errors;
+});
+
+process.on('exit', function() {
+ process.removeAllListeners('uncaughtException');
+ assert.equal(errors, win32 ? 1 : 2);
+});
@bnoordhuis

Why should this throw?

@koichik

Sorry, I have a poor memory, I don't remember...
Probably, this test just checked the message string, it did not care about whether an exception should be throws (It is the meaning of "this patch does not fix the main problem").

Please sign in to comment.
Something went wrong with that request. Please try again.