spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

RangeError: Invalid typed array length: -4095 #363

Open boompig opened 4 years ago

boompig commented 4 years ago

I'm trying to get express + spdy working together. I followed this walkthrough and encountered an error.

I'm pared down the example to a very simple case that consistently fails with the error below. I don't believe I'm making any obvious mistakes. To reproduce the error, visit the URL (server starts without errors).

$ node index.js
Running on https://localhost:8080
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> (/Users/XXXXXX/node_modules/handle-thing/lib/handle.js:88:10)
    at Stream.emit (events.js:205:15)
    at endReadableNT (/Users/XXXXXX/node_modules/readable-stream/lib/_stream_readable.js:1077:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)

Using this code:

const fs = require('fs');
const express = require('express');
const spdy = require('spdy');

// constants
const port = process.env.PORT || 8080;

// app config
const app = express();
const options = {
    key: fs.readFileSync('certs/myserver.key'),
    cert: fs.readFileSync('certs/certbundle.pem'),
};

// routes
app.use('/', express.static('public'));

spdy.createServer(options, app).listen(port, (err) => {
    if(err) {
        console.error(err);
        return process.exit(1);
    }
    console.log(`Running on https://localhost:${port}`);
});

I have latest express and spdy:

{
  "devDependencies": {
    "express": "^4.17.1",
    "spdy": "^4.0.1"
  }
}

node version v12.4.0

Is this possibly related to this issue?

boompig commented 4 years ago

Small additions:

  1. public directory exists with index.html inside it.
  2. If I remove spdy and replace it with app.listen and visit the non-https URL then the server works as expected

Therefore I believe this is a bug with spdy module

chranmat commented 4 years ago

I also have this issue. I'm not using spdy directly, but through another module.

AliasPedroKarim commented 4 years ago

I work with spdy and it shows me the same error when I try to run the server

internal/buffer.js:788
class FastBuffer extends Uint8Array {}
^

RangeError: Invalid typed array length: -4095
    at new Uint8Array (<anonymous>)
    at new FastBuffer (internal/buffer.js:788:1)
    at Handle.onStreamRead [as onread] (internal/stream_base_commons.js:149:17)
    at Stream.<anonymous> (/home/xxxxxx/node_modules/handle-thing/lib/handle.js:88:10)
    at Stream.emit (events.js:202:15)
    at endReadableNT (/home/xxxxxx/node_modules/spdy-transport/node_modules/readable-stream/lib/_stream_readable.js:1077:12)
SlyCaptainFlint commented 4 years ago

I am also hitting the same issue when using express+spdy. Seems to go away if I disable the h2 protocol and don't attempt to provide a certificate, but that is the whole reason I want to use spdy in the first place.

2234839 commented 4 years ago

I'm trying to get express + spdy working together. I followed this walkthrough and encountered an error.

I'm pared down the example to a very simple case that consistently fails with the error below. I don't believe I'm making any obvious mistakes. To reproduce the error, visit the URL (server starts without errors).

$ node index.js
Running on https://localhost:8080
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> (/Users/XXXXXX/node_modules/handle-thing/lib/handle.js:88:10)
    at Stream.emit (events.js:205:15)
    at endReadableNT (/Users/XXXXXX/node_modules/readable-stream/lib/_stream_readable.js:1077:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)

Using this code:

const fs = require('fs');
const express = require('express');
const spdy = require('spdy');

// constants
const port = process.env.PORT || 8080;

// app config
const app = express();
const options = {
  key: fs.readFileSync('certs/myserver.key'),
  cert: fs.readFileSync('certs/certbundle.pem'),
};

// routes
app.use('/', express.static('public'));

spdy.createServer(options, app).listen(port, (err) => {
  if(err) {
      console.error(err);
      return process.exit(1);
  }
  console.log(`Running on https://localhost:${port}`);
});

I have latest express and spdy:

{
  "devDependencies": {
    "express": "^4.17.1",
    "spdy": "^4.0.1"
  }
}

node version v12.4.0

Is this possibly related to this issue?

是的,与node的版本有关 10 的版本没问题,我升级之后也遇到了相同的问题 Yes, there is no problem with the node version 10, I had the same problem with the upgrade

newlukai commented 4 years ago

The same for me. Node@12.13.0 express@4.17.1 spdy@4.0.1

UPDATE: The referenced fix works for me.

calaway commented 4 years ago

Can you please elaborate what the fix is for this issue?

I'm running into the same error on Node 12.8.1, but it works when I revert to Node 10.15.3. Is there a way to resolve the error on Node 12?

I really appreciate your help!

luki1412 commented 4 years ago

Still broken on v12.14.1 and seems like no active maintainers.

gareth-johnstone commented 4 years ago

we're also having the same issues with SPDY

Is this even maintained??

coxrichuk commented 4 years ago

I am also experiencing this issue

node@13.5.0 express@4.14.0 spdy@3.3.3

Very simple app

const port = 3008;
const spdy = require('spdy');
const express = require('express');
const path = require('path');
const fs = require('fs');

const app = express()

app.get('*', (req, res) => {
    res
      .status(200)
      .json({message: 'ok'})
})
const options = {
    key: fs.readFileSync(__dirname + '/server.key'),
    cert:  fs.readFileSync(__dirname + '/server.cert')
}
console.log(options)
spdy
  .createServer(options, app)
  .listen(port, (error) => {
    if (error) {
      console.error(error)
      return process.exit(1)
    } else {
      console.log('Listening on port: ' + port + '.')
    }
  })
evandrix commented 4 years ago

bump

macOS Catalina 10.15.3 Node.JS v13.8.0

workaround right now is https://github.com/nvm-sh/nvm + v10.19.0

StephanBijzitter commented 3 years ago

It's fixed. When you update, make sure to manually inspect your yarn or npm lock file. handle-thing (great name) must be at least at version 2.0.1

Smileytear commented 1 year ago

It's fixed. When you update, make sure to manually inspect your yarn or npm lock file. handle-thing (great name) must be at least at version 2.0.1

you are right, update webpack version can solve this quesiton