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

HTTP2 Proxy always falls #51

Closed
borodadada opened this issue Apr 17, 2019 · 14 comments
Closed

HTTP2 Proxy always falls #51

borodadada opened this issue Apr 17, 2019 · 14 comments
Labels

Comments

@borodadada
Copy link

borodadada commented Apr 17, 2019

Hello, i fastify user, and now i needed proxy server, i install fastify proxy and set basic settings.
This my server -


const proxy = require('fastify-http-proxy')
const fastify = require('fastify')({
    logger: false,
    http2: true,
    https: {
        key: fs.readFileSync(path.join(serverDirectory, '/certificate/', 'key.pem')),
        cert: fs.readFileSync(path.join(serverDirectory, '/certificate/', 'domain.crt')),
        ca: [
            fs.readFileSync(path.join(serverDirectory, '/certificate/', 'USERTrustRSAAddTrustCA.crt')),
            fs.readFileSync(path.join(serverDirectory, '/certificate/', 'AddTrustExternalCARoot.crt')),
            fs.readFileSync(path.join(serverDirectory, '/certificate/', 'SectigoRSADomainValidationSecureServerCA.crt')),
        ]
    }
})

fastify.register(proxy, {
    upstream: 'https://localhost:3000',
    prefix: '/back', // optional
    http2: true // optional
})

I use SSL from domain, after request i use sort for several servers...
One problem, fastyfy proxy always falls!!!

Error

[nodemon] starting `node ./server/index.js`
internal/http2/compat.js:567
      throw new ERR_HTTP2_INVALID_STREAM();
      ^

Error [ERR_HTTP2_INVALID_STREAM]: The stream has been destroyed
    at Http2ServerResponse.writeHead (internal/http2/compat.js:567:13)
    at onSendEnd (D:\js\proxy\node_modules\fastify\lib\reply.js:308:7)
    at onSendHook (D:\js\proxy\node_modules\fastify\lib\reply.js:261:5)
    at handleError (D:\js\proxy\node_modules\fastify\lib\reply.js:418:5)
    at onErrorHook (D:\js\proxy\node_modules\fastify\lib\reply.js:373:5)
    at _Reply.Reply.send (D:\js\proxy\node_modules\fastify\lib\reply.js:98:5)
    at defaultErrorHandler (D:\js\proxy\node_modules\fastify\lib\context.js:34:9)
    at handleError (D:\js\proxy\node_modules\fastify\lib\reply.js:401:18)
    at onErrorHook (D:\js\proxy\node_modules\fastify\lib\reply.js:373:5)
    at _Reply.Reply.send (D:\js\proxy\node_modules\fastify\lib\reply.js:98:5)
[nodemon] app crashed - waiting for file changes before starting...

In version 1.* this same problem

  "dependencies": {
    "fastify": "^2.2.0",
    "fastify-http-proxy": "^2.1.0"
  }
@mcollina
Copy link
Member

which version of Node.js are you using?
Can you also include the code for your server running at localhost:3000?

@borodadada
Copy link
Author

borodadada commented Apr 17, 2019

i use Node js node-v10.15.3-x64 LTS

fastify.listen(443, '0.0.0.0', (err, address) => {
    if (err) {
        fastify.log.error(err)
        process.exit(1)
    }
    fastify.log.info(`server listening on ${address}`)
})

i need only redirect from my domain on my servers

fastify.register(proxy, {
    upstream: 'https://localhost:3000',
    prefix: '/back', // optional
    http2: true // optional
})
  
fastify.register(proxy, {
    upstream: 'https://localhost:3001',
    prefix: '/', // optional
    http2: true // optional
})

One request work file
https://mydomain.com
redirect work fine
Refresh page and server down

Server port 3000

const fastify = require('fastify')({
    logger: false,
    http2: true,
    https: {
        key: fs.readFileSync(path.join(serverDirectory, '/certificate/localhost/', 'key.pem')),
        cert: fs.readFileSync(path.join(serverDirectory, '/certificate/localhost/', 'cert.pem'))
    }
});

fastify.listen(3000, '0.0.0.0', (err, address) => {
    console.log(address)
    if (err) {
        fastify.log.error(err)
        process.exit(1)
    }
    fastify.log.info(`server listening on ${address}`)
})

@mcollina
Copy link
Member

Ouch, it's a bug in Node core - I thought I fixed it in nodejs/node#24723, but I didn't. Unfortunately it'll have to get fixed there first.

@borodadada
Copy link
Author

remains await new node js
mcollina thanks for info

mcollina added a commit to mcollina/node that referenced this issue May 17, 2019
The http1 implementation does not throw if the connection is down.
The http2 compat implementation should do the same.

See: fastify/fastify-http-proxy#51.
See: fastify/fastify#1494.
mcollina added a commit to nodejs/node that referenced this issue May 18, 2019
The http1 implementation does not throw if the connection is down.
The http2 compat implementation should do the same.

See: fastify/fastify-http-proxy#51.
See: fastify/fastify#1494.

PR-URL: #27682
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
targos pushed a commit to nodejs/node that referenced this issue May 20, 2019
The http1 implementation does not throw if the connection is down.
The http2 compat implementation should do the same.

See: fastify/fastify-http-proxy#51.
See: fastify/fastify#1494.

PR-URL: #27682
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
@mokimo
Copy link

mokimo commented Nov 13, 2019

Is this solved @borodadada ?

@borodadada
Copy link
Author

@mokimo sorry, I will test later

@stale
Copy link

stale bot commented Oct 21, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 21, 2020
@stale stale bot closed this as completed Nov 1, 2020
@kostia1st
Copy link

I believe this is still an issue though, as of node@12

@mcollina mcollina reopened this Feb 5, 2021
@mcollina mcollina added bug and removed stale labels Feb 5, 2021
@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

I believe this is still an issue though, as of node@12

which version?

Could you test on node v14?

@kostia1st
Copy link

Seems like it does not work in node@15 either (node:alpine from here https://hub.docker.com/_/node/ as of today).
I will check it in node@14 LTS locally w/o Docker shortly.

Also, I'm not 100% sure this is the issue in question. For me the symptoms are that the DELETE command with no body causes the error:

err: {
       "type": "NodeError",
       "message": "write after end",
       "stack":
           Error [ERR_STREAM_WRITE_AFTER_END]: write after end
               at writeAfterEnd (_stream_writable.js:264:14)
               at ClientHttp2Stream.Writable.write (_stream_writable.js:313:5)
               at ClientHttp2Stream.Writable.end (_stream_writable.js:623:10)
               at end (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify-reply-from\lib\request.js:184:9)
               at handleHttp2Req (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify-reply-from\lib\request.js:149:7)
               at _Reply.from (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify-reply-from\index.js:103:5)
               at Object.handler (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify-http-proxy\index.js:163:11)
               at preHandlerCallback (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify\lib\handleRequest.js:124:28)
               at preValidationCallback (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify\lib\handleRequest.js:107:5)
               at handler (C:\Root\Dev\repair-tool\packages\fe-server\node_modules\fastify\lib\handleRequest.js:70:7)
       "code": "ERR_STREAM_WRITE_AFTER_END"
}

once I disable ( http2: false ) everything works as expected

@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

It's not. It's likely a different one.. this one is a process crash.

Open a new issue with a repro.

@mcollina mcollina closed this as completed Feb 5, 2021
@kostia1st
Copy link

The "process" actually does not crash, only that one particular request.
And yes, node v14.15.4 still has this.

@mcollina
Copy link
Member

mcollina commented Feb 5, 2021

The "process" actually does not crash, only that one particular request.
And yes, node v14.15.4 still has this.

These two sentences contradicts each other. This issue was about the process crashing. If it's not crashing, then it's not this issue.

@kostia1st
Copy link

Ah, I misunderstood your reference "this issue". Alrighty then.

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

No branches or pull requests

4 participants