Skip to content
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

src: add UV_PIPE_NO_TRUNCATE for bind in pipe_wrap.cc #52347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ sockets on other operating systems.
[`socket.connect()`][] take a `path` parameter to identify IPC endpoints.

On Unix, the local domain is also known as the Unix domain. The path is a
file system pathname. It gets truncated to an OS-dependent length of
`sizeof(sockaddr_un.sun_path) - 1`. Typical values are 107 bytes on Linux and
103 bytes on macOS. If a Node.js API abstraction creates the Unix domain socket,
it will unlink the Unix domain socket as well. For example,
[`net.createServer()`][] may create a Unix domain socket and
file system pathname. It will throw an error when the length of pathname is
greater than the length of `sizeof(sockaddr_un.sun_path)`. Typical values are
107 bytes on Linux and 103 bytes on macOS. If a Node.js API abstraction creates
the Unix domain socket, it will unlink the Unix domain socket as well. For
example, [`net.createServer()`][] may create a Unix domain socket and
[`server.close()`][] will unlink it. But if a user creates the Unix domain
socket outside of these abstractions, the user will need to remove it. The same
applies when a Node.js API creates a Unix domain socket but the program then
Expand Down
11 changes: 8 additions & 3 deletions src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ void PipeWrap::Bind(const FunctionCallbackInfo<Value>& args) {
PipeWrap* wrap;
ASSIGN_OR_RETURN_UNWRAP(&wrap, args.Holder());
node::Utf8Value name(args.GetIsolate(), args[0]);
int err = uv_pipe_bind2(&wrap->handle_, *name, name.length(), 0);
int err =
uv_pipe_bind2(&wrap->handle_, *name, name.length(), UV_PIPE_NO_TRUNCATE);
args.GetReturnValue().Set(err);
}

Expand Down Expand Up @@ -225,8 +226,12 @@ void PipeWrap::Connect(const FunctionCallbackInfo<Value>& args) {

ConnectWrap* req_wrap =
new ConnectWrap(env, req_wrap_obj, AsyncWrap::PROVIDER_PIPECONNECTWRAP);
int err = req_wrap->Dispatch(
uv_pipe_connect2, &wrap->handle_, *name, name.length(), 0, AfterConnect);
int err = req_wrap->Dispatch(uv_pipe_connect2,
&wrap->handle_,
*name,
name.length(),
UV_PIPE_NO_TRUNCATE,
AfterConnect);
if (err) {
delete req_wrap;
} else {
Expand Down
36 changes: 36 additions & 0 deletions test/parallel/test-net-pipe-with-long-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const fs = require('fs');
const tmpdir = require('../common/tmpdir');
tmpdir.refresh();

// Test UV_PIPE_NO_TRUNCATE

// See pipe_overlong_path in https://github.com/libuv/libuv/blob/master/test/test-pipe-bind-error.c
if (common.isWindows) {
common.skip('UV_PIPE_NO_TRUNCATE is not supported on window');
}

// See https://github.com/libuv/libuv/issues/4231
const pipePath = `${tmpdir.path}/${'x'.repeat(10000)}.sock`;

const server = net.createServer()
.listen(pipePath)
// It may work on some operating systems
.on('listening', () => {
// The socket file must exsit
assert.ok(fs.existsSync(pipePath));
const socket = net.connect(pipePath, common.mustCall(() => {
socket.destroy();
server.close();
}));
})
.on('error', (error) => {
assert.ok(error.code === 'EINVAL', error.message);
net.connect(pipePath)
.on('error', common.mustCall((error) => {
assert.ok(error.code === 'EINVAL', error.message);
}));
});