From 4bc1cccb228fdfd1a527de0ee1d9cedc6dac87e2 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 27 Mar 2016 21:08:29 -0400 Subject: [PATCH] dgram: pass null as error on successful send() Prior to c9fd9e21622abb7b3893af457f6aaafb2363ab46, UDP sockets would callback with a null error on successful send() calls. The current behavior is to pass 0 as the error. This commit restores the previous, more expected behavior. PR-URL: https://github.com/nodejs/node/pull/5929 Reviewed-By: Evan Lucas Reviewed-By: Rich Trott Reviewed-By: Brian White --- lib/dgram.js | 3 +++ test/parallel/test-dgram-send-callback-buffer.js | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/dgram.js b/lib/dgram.js index 5ac06b40f7c6d0..4473282148fdff 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -392,7 +392,10 @@ function doSend(ex, self, ip, buffer, address, port, callback) { function afterSend(err, sent) { if (err) { err = exceptionWithHostPort(err, 'send', this.address, this.port); + } else { + err = null; } + this.callback(err, sent); } diff --git a/test/parallel/test-dgram-send-callback-buffer.js b/test/parallel/test-dgram-send-callback-buffer.js index e877b8d73bdeb9..e2966645d927ae 100644 --- a/test/parallel/test-dgram-send-callback-buffer.js +++ b/test/parallel/test-dgram-send-callback-buffer.js @@ -9,6 +9,7 @@ const client = dgram.createSocket('udp4'); const buf = Buffer.allocUnsafe(256); const onMessage = common.mustCall(function(err, bytes) { + assert.strictEqual(err, null); assert.equal(bytes, buf.length); clearTimeout(timer); client.close();