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

hyco-https + express.js = TypeError: requestChannel.pendingRequest.handleBody is not a function #30

Open
rubinovk opened this issue Apr 4, 2019 · 4 comments

Comments

@rubinovk
Copy link

rubinovk commented Apr 4, 2019

Actual Behavior

  1. Create listener with express:
const http = require('http')
const https = require('hyco-https')
http.ServerResponse = https.ServerResponse
const express = require('express')
var app = express()

var uri = https.createRelayListenUri(ns, path)
var server = https.createRelayedServer(
  {
    server: uri,
    token: () => https.createRelayToken(uri, keyrule, key)
  },
  app
)

app.post('/my-hc', (req, res) => {
  console.log('received')
  res.status(200).send('hey')
})

server.listen()
  1. Sender connects and sends data
  2. Listener receives the request on app.post('/my-hc') and crashes with
hyco-https\lib\HybridConnectionHttpsServer.js:653
      requestChannel.pendingRequest.handleBody(event.data);
                                    ^
TypeError: requestChannel.pendingRequest.handleBody is not a function
  1. If the sent data was roughly < 50 KB then no response is sent and sender also crashes with Error: read ECONNRESET at TLSWrap.onread (net.js:622:25)
  2. If the sent data was roughly > 50KB then response is sent and sender gets status 200 and does not crash.

Note: same scenario works OK without express.js integration.

Expected Behavior

No crashing

Versions

  • OS platform and version: Win 10
  • Node Version: 10.15.3
  • NPM package version or commit ID: "express": "^4.16.4", "hyco-https": "^1.3.0",
@anxious-coder-lhs
Copy link

Same issue.

@curtiskeisler
Copy link

curtiskeisler commented Jan 16, 2020

I'm having the same issue when I use Express and body-parser to process a post similar to the above.

I triaged the issue a little and found that on this line:

server.pendingRequest.handleBody(event.data);

. . . the pendingRequest doesn't have a handleBody method. It appears in my debugger in VS Code that it is an IncomingMessage object.

However, when I inspect the object, the handleBody method is not there (which is the error reported above).

IncomingMessage is defined in the HybridConnectionHttpsServer.js file here:

const { IncomingMessage } = require('./_hyco_incoming');

and here's the function that we are looking for:

IncomingMessage.prototype.handleBody = function handleBody(buf) {

It's as if there are multiple IncomingMessage classes derived from different sources.

Perhaps this messages needs to be recast or something?

Also, something odd I saw is that this code directly below the IncomingMessage definition above

//const PerMessageDeflate = wsc.require('./lib/PerMessageDeflate');

is commented out but later, there is code that uses those constants as shown here:

if (options && offer[PerMessageDeflate.extensionName]) {

My guess is that if that code is ever hit, it will fail. Being in proximity to this and other comments, I wonder if that commenting out or a related check may have introduced an issue here?

Purely speculation!

@jfggdl
Copy link

jfggdl commented Oct 27, 2020

Thanks for reporting this issue.

@diegohexi
Copy link
Contributor

Pull request created for this fix #56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants