Not working will unix sockets
jasnell opened this issue · 2 comments
@mcollina @sebdeckers ... here's a fun todo ... we're currently not working 100% correctly with unix sockets... here's a test case:
// Flags: --expose-http2
'use strict';
const common = require('../common');
const assert = require('assert');
const http2 = require('http2');
const server = http2.createServer();
server.on('stream', common.mustCall((stream) => {
stream.end('abcxyz');
let actual = '';
stream.setEncoding('utf8');
stream.on('data', (chunk) => actual += chunk);
stream.on('end', common.mustCall(() => assert.strictEqual(actual, 'abcxyz')));
}));
server.listen(common.PIPE, common.mustCall(() => {
const options = {
socketPath: common.PIPE,
path: '/'
};
const client = http2.connect(options);
const req = client.request({ ':method': 'POST' });
req.end('abcxyz');
let actual = '';
req.setEncoding('utf8');
req.on('data', (chunk) => actual += chunk);
req.on('end', common.mustCall(() => assert.strictEqual(actual, 'abcxyz')));
req.on('streamClosed', common.mustCall(() => {
client.destroy();
server.close();
}));
}));
Overall, this should just work, as the fact that it's a unix socket should be completely transparent to the http2 implementation details. Something definitely is not working tho...
$ ./node --expose-http2 test/parallel/test-http2-unix-socket.js
(node:19644) ExperimentalWarning: The http2 module is an experimental API.
assert.js:48
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: '' === 'abcxyz'
at ClientHttp2Stream.req.on.common.mustCall (/home/james/node/http2-jasnell/test/parallel/test-http2-unix-socket.js:29:46)
at ClientHttp2Stream.<anonymous> (/home/james/node/http2-jasnell/test/common/index.js:516:15)
at emitNone (events.js:110:20)
at ClientHttp2Stream.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
I will be looking into it more, but if either of you get an opportunity, go for it!
FWIW, just had a quick look at it. The server side appears to function correctly. Successfully connected using h2load
to the UNIX domain socket. And the Node.js http2
client even receives the data in its buffer, but does not emit the data
event.
Note to self
h2load -v -B unix:/Users/seb/Code/nodejs/http2/test/tmp/test.sock.85349 http://localhost/
@jasnell I believe the above test case has some misplaced (?) code in the server:stream
event handler. Receiving data is being tested in the client section.
Edit: Never mind.