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

feat(node/net): unix domain socket support #2146

Merged
merged 37 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0c8219c
feat: first pass support of node pipe compat
cmorten Apr 23, 2022
46ce57b
test: `test-net-server-listen-path.js`
cmorten Apr 23, 2022
107d6f5
test: add net coverage
cmorten Apr 23, 2022
ecab3c0
test: reinstate most of `test-net-server-listen-path`
cmorten Apr 23, 2022
7c83511
refactor: remove log statement
cmorten Apr 23, 2022
492f5cc
refactor: windows named pipes aren't supported yet
cmorten Apr 24, 2022
e561e4f
test: windows names pipes not yet supported
cmorten Apr 24, 2022
5c8a96f
fix: ignore windows not other way around :facepalm:
cmorten Apr 24, 2022
6953b93
feat: support `LibuvStreamWrap.prototype.writev`
cmorten Apr 24, 2022
af69557
test: `test-net-buffersize.js`
cmorten Apr 24, 2022
b7ee3ce
fmt: net.ts
cmorten Apr 24, 2022
7257a56
fix: windows listening on ::1 but trying to connect to 127.0.0.1
cmorten Apr 25, 2022
f7a4f5b
revert: dns record reordering
cmorten Apr 25, 2022
85dcfed
revert: default ipv6
cmorten Apr 25, 2022
1c8d332
test: coverage
cmorten Apr 25, 2022
2cbcb38
fix: formatting
cmorten Apr 25, 2022
16973a3
revert: remove console line
cmorten Apr 26, 2022
3fb6169
revert: address orders
cmorten Apr 26, 2022
ea38d45
feat: set address for connections created by internals
cmorten Apr 26, 2022
ac62689
test: drive out behaviours with tests
cmorten Apr 26, 2022
bbdf5bf
fix: formatting
cmorten Apr 26, 2022
4d191c0
fix: force windows to IPv4 with implicit binding
cmorten Apr 27, 2022
860a521
fix: formatting
cmorten Apr 27, 2022
52b436a
test: expand net test coverage
cmorten Apr 27, 2022
c94a872
test: fix ignores on tests that needed adjustment
cmorten Apr 27, 2022
20953bd
test: remove net stream test as fails on Windows
cmorten Apr 27, 2022
b9feed9
Merge branch 'main' into feat/node_net_pipe
cmorten Apr 30, 2022
cf8eb21
fix: merge conflicts with new dns module changes
cmorten May 1, 2022
ae554c2
test: increase net coverage
cmorten May 2, 2022
7b47cda
fix: formatting
cmorten May 2, 2022
9df5d98
revert: modifications fail duplex tests
cmorten May 2, 2022
abc862d
revert: windows says otherwise
cmorten May 2, 2022
7b32df6
Merge branch 'main' into feat/node_net_pipe
cmorten May 5, 2022
06d3258
feat: support unstable deno strategy
cmorten May 5, 2022
942b49e
fix: formatting
cmorten May 5, 2022
dd468c9
fix: types for `_deno_unstable.ts`
cmorten May 5, 2022
a388546
fix: don't swallow errors in unstable
cmorten May 5, 2022
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
14 changes: 14 additions & 0 deletions _deno_unstable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// @ts-nocheck Bypass static errors for missing --unstable.

export type HttpClient = Deno.HttpClient;
export type UnixConnectOptions = Deno.UnixConnectOptions;
export type UnixListenOptions = Deno.UnixListenOptions;

export function addSignalListener(
...args: Parameters<typeof Deno.addSignalListener>
Expand Down Expand Up @@ -153,6 +155,18 @@ export function networkInterfaces(
}
}

export async function connect(
options: UnixConnectOptions,
): Promise<Deno.UnixConn> {
return await Deno.connect(options);
}

export function listen(
options: UnixListenOptions & { transport: "unix" },
): ReturnType<typeof Deno.listen> {
return Deno.listen(options);
}

export function ListenerRef(
listener: Deno.Listener,
...args: Parameters<Deno.Listener["ref"]>
Expand Down
2 changes: 1 addition & 1 deletion node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ workflow.
$ deno task node:setup
```

You can aditionally pass the `-y`/`-n` flag to use test cache or generating
You can additionally pass the `-y`/`-n` flag to use test cache or generating
tests from scratch instead of being prompted at the moment of running it.

```zsh
Expand Down
1 change: 1 addition & 0 deletions node/_events.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ export function getEventListeners(emitterOrTarget, type) {
return emitterOrTarget.listeners(type);
}
if (emitterOrTarget instanceof EventTarget) {
// TODO: kEvents is not defined
const root = emitterOrTarget[kEvents].get(type);
const listeners = [];
let handler = root?.next;
Expand Down
2 changes: 1 addition & 1 deletion node/_tools/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const ignoreList = Object.entries(config.ignore).reduce(
export function getPathsFromTestSuites(suites: TestSuites): string[] {
const testPaths: string[] = [];
for (const [dir, paths] of Object.entries(suites)) {
if (dir === "parallel" || dir === "internet") {
if (["parallel", "internet", "pummel"].includes(dir)) {
for (const path of paths) {
testPaths.push(join(dir, path));
}
Expand Down
101 changes: 101 additions & 0 deletions node/_tools/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
"test-fs-rmdir-recursive.js",
"test-fs-write-file.js",
"test-fs-write.js",
"test-net-better-error-messages-path.js",
"test-net-connect-buffer.js",
"test-net-connect-buffer2.js",
"test-net-end-close.js",
"test-net-listen-invalid-port.js",
"test-net-server-call-listen-multiple-times.js",
"test-net-server-listen-path.js",
"test-net-server-try-ports.js",
"test-net-socket-timeout.js",
"test-net-write-arguments.js",
"test-os.js",
"test-path-resolve.js",
"test-path.js",
Expand All @@ -56,6 +66,10 @@
"test-zlib-write-after-flush.js",
"test-zlib-zero-byte.js",
"test-zlib-zero-windowBits.js"
],
"pummel": [
"test-net-bytes-per-incoming-chunk-overhead.js",
"test-net-write-callbacks.js"
]
},
"tests": {
Expand Down Expand Up @@ -225,7 +239,85 @@
"test-http-url.parse-path.js",
"test-http-url.parse-post.js",
"test-http-url.parse-search.js",
"test-net-access-byteswritten.js",
"test-net-after-close.js",
"test-net-allow-half-open.js",
"test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-listen.js",
"test-net-better-error-messages-path.js",
"test-net-better-error-messages-port-hostname.js",
"test-net-bind-twice.js",
"test-net-buffersize.js",
"test-net-bytes-written-large.js",
"test-net-can-reset-timeout.js",
"test-net-connect-after-destroy.js",
"test-net-connect-buffer.js",
"test-net-connect-buffer2.js",
"test-net-connect-call-socket-connect.js",
"test-net-connect-destroy.js",
"test-net-connect-immediate-destroy.js",
"test-net-connect-immediate-finish.js",
"test-net-connect-no-arg.js",
"test-net-connect-options-ipv6.js",
"test-net-connect-options-port.js",
"test-net-dns-custom-lookup.js",
"test-net-dns-error.js",
"test-net-dns-lookup-skip.js",
"test-net-dns-lookup.js",
"test-net-during-close.js",
"test-net-eaddrinuse.js",
"test-net-end-close.js",
"test-net-end-destroyed.js",
"test-net-end-without-connect.js",
"test-net-isip.js",
"test-net-isipv4.js",
"test-net-isipv6.js",
"test-net-listen-after-destroying-stdin.js",
"test-net-listen-close-server-callback-is-not-function.js",
"test-net-listen-close-server.js",
"test-net-listen-error.js",
"test-net-listen-invalid-port.js",
"test-net-listening.js",
"test-net-local-address-port.js",
"test-net-localerror.js",
"test-net-options-lookup.js",
"test-net-pause-resume-connecting.js",
"test-net-persistent-ref-unref.js",
"test-net-pipe-connect-errors.js",
"test-net-remote-address-port.js",
"test-net-server-call-listen-multiple-times.js",
"test-net-server-capture-rejection.js",
"test-net-server-close.js",
"test-net-server-listen-options-signal.js",
"test-net-server-listen-options.js",
"test-net-server-listen-path.js",
"test-net-server-listen-remove-callback.js",
"test-net-server-max-connections.js",
"test-net-server-options.js",
"test-net-server-pause-on-connect.js",
"test-net-server-try-ports.js",
"test-net-server-unref-persistent.js",
"test-net-server-unref.js",
"test-net-socket-close-after-end.js",
"test-net-socket-connect-without-cb.js",
"test-net-socket-connecting.js",
"test-net-socket-destroy-send.js",
"test-net-socket-destroy-twice.js",
"test-net-socket-end-before-connect.js",
"test-net-socket-end-callback.js",
"test-net-socket-no-halfopen-enforcer.js",
"test-net-socket-ready-without-cb.js",
"test-net-socket-timeout.js",
"test-net-socket-write-after-close.js",
"test-net-socket-write-error.js",
"test-net-sync-cork.js",
"test-net-timeout-no-handle.js",
"test-net-writable.js",
"test-net-write-after-end-nt.js",
"test-net-write-arguments.js",
"test-net-write-fully-async-buffer.js",
"test-net-write-fully-async-hex-string.js",
"test-net-write-slow.js",
"test-next-tick-doesnt-hang.js",
"test-next-tick-fixed-queue-regression.js",
"test-next-tick-intentional-starvation.js",
Expand Down Expand Up @@ -470,6 +562,11 @@
"test-zlib-write-after-flush.js",
"test-zlib-zero-byte.js",
"test-zlib-zero-windowBits.js"
],
"pummel": [
"test-net-bytes-per-incoming-chunk-overhead.js",
"test-net-pingpong-delay.js",
"test-net-write-callbacks.js"
]
},
"windowsIgnore": {
Expand All @@ -486,6 +583,10 @@
"test-fs-write-file-sync.js",
"test-fs-write-file.js",
"test-http-client-reject-cr-no-lf.js",
"test-net-better-error-messages-listen-path.js",
"test-net-better-error-messages-path.js",
"test-net-pipe-connect-errors.js",
"test-net-server-listen-path.js",
"test-util-inspect-getters-accessing-this.js",
"test-util-inspect-long-running.js",
"test-util-inspect.js"
Expand Down
2 changes: 1 addition & 1 deletion node/_tools/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { downloadFile } from "../../_util/download_file.ts";
*
* Usage: `deno run --allow-read --allow-net --allow-write setup.ts`
*
* You can aditionally pass a flag to indicate if cache should be used for generating
* You can additionally pass a flag to indicate if cache should be used for generating
* the tests, or to generate the tests from scratch (-y/-n)
*/

Expand Down
10 changes: 10 additions & 0 deletions node/_tools/test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*/
'use strict';
const assert = require("assert");
const path = require("path");
const util = require("util");
const tmpdir = require("./tmpdir");

function platformTimeout(ms) {
return ms;
Expand Down Expand Up @@ -345,6 +347,13 @@ function skip(msg) {
process.exit(0);
}

const PIPE = (() => {
const localRelative = path.relative(process.cwd(), `${tmpdir.path}/`);
const pipePrefix = isWindows ? "\\\\.\\pipe\\" : localRelative;
const pipeName = `node-test.${process.pid}.sock`;
return path.join(pipePrefix, pipeName);
})();

function getArrayBufferViews(buf) {
const { buffer, byteOffset, byteLength } = buf;

Expand Down Expand Up @@ -387,6 +396,7 @@ module.exports = {
mustCallAtLeast,
mustNotCall,
mustSucceed,
PIPE,
platformTimeout,
printSkipMessage,
skipIfDumbTerminal,
Expand Down
28 changes: 28 additions & 0 deletions node/_tools/test/parallel/test-net-access-byteswritten.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');

const assert = require('assert');
const net = require('net');
const tls = require('tls');
const tty = require('tty');

// Check that the bytesWritten getter doesn't crash if object isn't
// constructed.
assert.strictEqual(net.Socket.prototype.bytesWritten, undefined);
assert.strictEqual(Object.getPrototypeOf(tls.TLSSocket).prototype.bytesWritten,
undefined);
assert.strictEqual(tls.TLSSocket.prototype.bytesWritten, undefined);
assert.strictEqual(Object.getPrototypeOf(tty.ReadStream).prototype.bytesWritten,
undefined);
assert.strictEqual(tty.ReadStream.prototype.bytesWritten, undefined);
assert.strictEqual(tty.WriteStream.prototype.bytesWritten, undefined);
58 changes: 58 additions & 0 deletions node/_tools/test/parallel/test-net-after-close.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

// 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.

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');

const server = net.createServer(common.mustCall((s) => {
console.error('SERVER: got connection');
s.end();
}));

server.listen(0, common.mustCall(() => {
const c = net.createConnection(server.address().port);
c.on('close', common.mustCall(() => {
/* eslint-disable no-unused-expressions */
console.error('connection closed');
assert.strictEqual(c._handle, null);
// Calling functions / accessing properties of a closed socket should not
// throw.
c.setNoDelay();
c.setKeepAlive();
c.bufferSize;
c.pause();
c.resume();
c.address();
c.remoteAddress;
c.remotePort;
server.close();
/* eslint-enable no-unused-expressions */
}));
}));
54 changes: 54 additions & 0 deletions node/_tools/test/parallel/test-net-allow-half-open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

'use strict';

const common = require('../common');
const assert = require('assert');
const net = require('net');

{
const server = net.createServer(common.mustCall((socket) => {
socket.end(Buffer.alloc(1024));
})).listen(0, common.mustCall(() => {
const socket = net.connect(server.address().port);
assert.strictEqual(socket.allowHalfOpen, false);
socket.resume();
socket.on('end', common.mustCall(() => {
process.nextTick(() => {
// Ensure socket is not destroyed straight away
// without proper shutdown.
assert(!socket.destroyed);
server.close();
});
}));
socket.on('finish', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.on('close', common.mustCall());
}));
}

{
const server = net.createServer(common.mustCall((socket) => {
socket.end(Buffer.alloc(1024));
})).listen(0, common.mustCall(() => {
const socket = net.connect(server.address().port);
assert.strictEqual(socket.allowHalfOpen, false);
socket.resume();
socket.on('end', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.end('asd');
socket.on('finish', common.mustCall(() => {
assert(!socket.destroyed);
}));
socket.on('close', common.mustCall(() => {
server.close();
}));
}));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file

// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 16.13.0
// This file is automatically generated by "node/_tools/setup.ts". Do not modify this file manually

'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const fp = '/blah/fadfa';
const server = net.createServer(common.mustNotCall());
server.listen(fp, common.mustNotCall());
server.on('error', common.mustCall(function(e) {
assert.strictEqual(e.address, fp);
}));
Loading