-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing to socket in Node.js 19 passes null
in callback
#47229
Comments
null
in callbacknull
in callback
Clarification: this is not specific to unix sockets. const net = require("net");
const server = net.createServer();
server.listen(
"localhost:8123",
function() {
const socket = new net.Socket();
socket.connect(
"localhost:8123",
function() {
socket.write(
"hello world",
function(x) {
console.log(x);
socket.destroy();
server.close();
}
);
}
)
}
); |
FWIW in general (not just node core) it's usually best to just do |
I don't think this counts as a regression because, to the best of my knowledge, the documentation doesn't claim anywhere that the If the change from undefined to null is a problem for you, then you're welcome to open a pull request to change it back. |
Aha, there seems to have been an issue complaining about the opposite problem :) Which resulted in this PR: I'd understand if this was changed across the codebase for a consistent API/UX, but it seems like it was changed only for
@bnoordhuis with this additional context, do you still feel like that? Thanks! |
cc @targos - this needs your input My suggestion: revert that change and declare that |
Why my input? I'm not familiar with this issue. |
Sorry, I meant @lpinca. |
I would personally not revert it. It was done for consistency (see #44290 (comment)) and in major release because it was known that it could break something. Anyway, I have no strong opinion. I'm fine either way. |
That's interesting, because it's completely counter to my own experience :) the comment says:
I've extensively wrapped the Node.js Other codepaths continue to use const net = require("net")
const server = net.createServer()
server.listen()
server.close(x => console.log(x))
|
The |
Thanks for the input. That's not how it's working currently :) const net = require("net")
const server = net.createServer()
server.close(x => console.log(typeof(x)))
|
Here are some examples: const fs = require('fs');
fs.open('test.txt', 'w', function (err, fd) {
console.log(err); // null
fs.write(fd, 'foo', function (err) {
console.log(err); // null
fs.close(fd, function (err) {
console.log(err); // null
});
});
}); const zlib = require('zlib');
zlib.deflate(Buffer.from('aaaaaaaaaa'), function (err, buf) {
console.log(err); // null
zlib.inflate(buf, function (err) {
console.log(err); // null
});
}); For |
Thanks! I guess I never encountered those due to using the Ok, so if |
I think so. The |
The blessed way to deal with it, in cases where there really even is a potential error, is to apply the robustness principle. Usually you'll use that first argument in a condition expression anyway, either bare or negated. If you use it in a way where undefined and null have a meaningfull difference, I suspect there might be a bigger problem in your code. |
IMHO the two paths from here are:
Personally I'm fine with (2) under the assumption that #44312 would be the last time this sort of change squeaks in 😁 but if these changes are going to keep happening, wouldn't it be better to decide on a consistent API and rip off the bandaid? |
When you use Typescript (depending on your tsconfig settings) this is typically not true and you do have to check for both. And nowadays, one might suspect a bigger problem in your code when you're not using Typescript ;). |
Version
v19.8.1
Platform
Linux armanbilge-sandbox-g0l1nfjuvbe 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior? Why is that the expected behavior?
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: