Bug 1875738

Summary: SPDY fails in node rh-nodejs14
Product: Red Hat Software Collections Reporter: Jan Houska <jhouska>
Component: nodejsAssignee: Jan Staněk <jstanek>
Status: CLOSED NOTABUG QA Contact: Jan Houska <jhouska>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rh-nodejs14CC: hhorak, jstanek, nodejs-maint, rhel-cs-apps-subsystem-qe, zsvetlik
Target Milestone: ---   
Target Release: 3.7   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1743558 Environment:
Last Closed: 2021-04-14 12:21:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1743558, 1885872, 1896454    
Bug Blocks: 1762839, 1896876, 1929312    

Description Jan Houska 2020-09-04 08:42:33 UTC
New rh-nodejs14 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 06:20:12 ] :: [   PASS   ] :: Running SPDY server and logging output (Expected 0, got 0)
:: [ 06:20:22 ] :: [   PASS   ] :: Giving server "10" seconds to start (Expected 0, got 0)
:: [ 06:20:22 ] :: [   PASS   ] :: Server should respond on regular HTTPS requests (Expected 0, got 0)
:: [ 06:20:22 ] :: [   FAIL   ] :: Server should respond on SPDY requests (Expected 0, got 1)
:: [ 06:20:22 ] :: [   FAIL   ] :: Stopping the server (Expected 0, got 1)
:: [ 06:20:23 ] :: [   PASS   ] :: Server should not be running (Expected 1, got 1)
:: [ 06:20:23 ] :: [   PASS   ] :: Output should contain "isSpdy: false" (Expected 0, got 0)
:: [ 06:20:23 ] :: [   PASS   ] :: Output should contain "isSpdy: true" (Expected 0, got 0)
:: [ 06:20:23 ] :: [   PASS   ] :: Attempt killing possibly leftover server process (Expected 0,1, got 1)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 11s
::   Assertions: 7 good, 2 bad
::   RESULT: FAIL



+++ This bug was initially created as a clone of Bug #1743558 +++

Description of problem:
Refer to this issue [1] for more info.

[1] https://github.com/spdy-http2/node-spdy/issues/350

Version-Release number of selected component (if applicable):
nodejs-12.4.0-1.module+el8.1.0+3505+d278616f.x86_64

How reproducible:
Always

Steps to Reproduce:
$ rpm -qa nodejs
nodejs-12.4.0-1.module+el8.1.0+3505+d278616f.x86_64

$ npm list
/mnt/tests/CoreOS/nodejs/Sanity/spdy-smoke
└─┬ spdy.1 -> /usr/lib/node_modules/spdy
  ├── debug.1 extraneous
  ├── handle-thing.0 extraneous
  ├── http-deceiver.7 extraneous
  ├── select-hose.0 extraneous
  └── spdy-transport.0 extraneous

$ cat server.js
var spdy = require('spdy'),
    fs = require('fs');

var options = {
  key: fs.readFileSync('./server-key.pem'),
  cert: fs.readFileSync('./server-cert.pem'),

  windowSize: 1024, // Server's window size
};

var server = spdy.createServer(options, function(req, res) {
  res.writeHead(200);

  var is_spdy = "false"
  if (req.isSpdy) { is_spdy = req.isSpdy.toString() }
  console.log("isSpdy: " + is_spdy);

  res.end('ok');
});

server.listen(8000);

$ cat client.js
var spdy = require('spdy'),
    http = require('http'),
    assert = require('assert');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

var port = 8000;

var agent = spdy.createAgent({
  host: 'localhost',
  port: port
});

http.get({
  protocol: 'https:',
  host: 'localhost',
  path: '/',
  port: port,
  agent: agent
}, function(response) {
  assert.equal(response.statusCode, 200);
  response.on('data', function(data) {
    assert.equal(data.toString(), 'ok');
    agent.close();
    process.exit(0);
  });
}).end();

$ nohup node server.js &
$ node client.js
(node:22072) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
(node:22072) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
events.js:177
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:183:27)
Emitted 'error' event at:
    at Connection.<anonymous> (/usr/lib/node_modules/spdy/lib/spdy/agent.js:149:12)
    at Connection.emit (events.js:200:13)
    at TLSSocket.onSocketError (/usr/lib/node_modules/spdy/node_modules/spdy-transport/lib/spdy-transport/connection.js:176:10)
    at TLSSocket.emit (events.js:205:15)
    at emitErrorNT (internal/streams/destroy.js:91:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:9) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}
[1]+  Exit 1                  nohup node server.js

Actual results:
$ cat nohup.out 
isSpdy: true
(node:11783) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
internal/buffer.js:941
class FastBuffer extends Uint8Array {}
^

RangeError: Invalid typed array length: -4095
    at new Uint8Array (<anonymous>)
    at new FastBuffer (internal/buffer.js:941:1)
    at Handle.onStreamRead [as onread] (internal/stream_base_commons.js:165:17)
    at Stream.<anonymous> (/usr/lib/node_modules/spdy/node_modules/handle-thing/lib/handle.js:88:10)
    at Stream.emit (events.js:205:15)
    at endReadableNT (/usr/lib/node_modules/spdy/node_modules/readable-stream/lib/_stream_readable.js:1077:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)


Expected results:
Request is served successfully

Additional info:
It is possible to work this around using the workaround mentioned in the issue [1]. After I've made changes to node_modules/spdy/node_modules/handle-thing/lib/handle.js file, the error's disappeared:

88 - self.onread(uv.UV_EOF, Buffer.alloc(0))
88 + self.onread(Buffer.alloc(0))

94 - self.onread(uv.UV_ECONNRESET, Buffer.alloc(0))
94 + self.onread(Buffer.alloc(0))

Comment 3 Jan Houska 2021-04-14 12:21:11 UTC
I propose to close. The problem was solved by update nodejs-spdy module to 4.0.2 version.  Test was fixed accordingly and it was added to the tier1 testing.