Comments (4)
Simplest reproduction:
const {PassThrough} = require('stream');
const think = () => new Promise((resolve, reject) => {
const p = new PassThrough();
process.nextTick(() => p.destroy(new Error('no way')));
resolve(p);
});
(async () => {
const stream = await think();
stream.once('error', () => {
console.log('Caught stream error');
});
})();
from http2-wrapper.
It is easily fixable for streams:
const {PassThrough} = require('stream');
const think = () => new Promise((resolve, reject) => {
const p = new PassThrough();
p.__destroy = p._destroy;
p._destroy = async (...args) => {
const callback = args.pop();
const next = Promise.resolve();
p.__destroy(...args, async error => {
await next;
callback(error);
});
};
process.nextTick(() => p.destroy(new Error('no way')));
resolve(p);
});
(async () => {
const stream = await think();
stream.once('error', () => {
console.log('Caught stream error');
});
})();
but unfortunately the we don't need to fix Http2Session
doesn't have a _destroy
agent.getSession()
because errors are handled by the parent - an Agent instance.
from http2-wrapper.
This is also applicable to Http2Session
:
const {connect} = require('http2');
const {TLSSocket} = require('tls');
const think = () => new Promise((resolve, reject) => {
const session = connect('https://httpbin.org', {
createConnection: (...args) => {
const socket = new TLSSocket();
process.nextTick(() => socket.destroy(new Error('oh no')));
return socket;
}
});
// session.once('error', () => {
// console.log('Error caught before await');
// });
resolve(session);
});
(async () => {
const session = await think();
session.once('error', () => {
console.log('Caught session error');
});
})();
from http2-wrapper.
An easy fix for Http2Session
(we can reemit error because it's not a stream):
const {connect} = require('http2');
const {TLSSocket} = require('tls');
const think = () => new Promise(async (resolve, reject) => {
const session = connect('https://httpbin.org', {
createConnection: (...args) => {
const socket = new TLSSocket();
process.nextTick(() => socket.destroy(new Error('oh no')));
return socket;
}
});
const promise = Promise.resolve();
const onError = async error => {
await promise;
session.emit('error', error);
};
session.once('error', onError);
resolve(session);
await promise;
session.off('error', onError);
});
(async () => {
const session = await think();
session.once('error', () => {
console.log('Caught session error');
});
})();
from http2-wrapper.
Related Issues (20)
- Support HTTPS servers without HTTP/2 support in auto.js
- Support sending request trailers
- Credentials `Proxy-Authorization` and `Authorization` headers are URL encoded, even though they shouldn't be
- Pass socket connection options in Agent HOT 3
- url.urlToHttpOptions(url) is not a function HOT 1
- error RequestError: read ECONNRESET HOT 4
- Adding `timeout` support to Proxy connection HOT 3
- `trailers` can get emitted before creating response HOT 1
- TypeError: Cannot set properties of null (setting 'trailers') HOT 4
- Test aborting via `signal`
- feature request: keep track of bandwidth usage HOT 7
- Http2OverHttp proxy still sends HTTP1.1 requests to target server. HOT 2
- Handle `GOAWAY` Frame HOT 1
- You broke GitHub HOT 1
- `agent › prevents session overloading #2` might be flaky
- Examples contain wrong path to load `cert.js` module HOT 1
- Repeat requests fail to reuse the first session HOT 1
- Destroy sessions when an error occurs HOT 6
- HTTP/2 pseudo headers should be converted/dropped when `auto` falls back to HTTP/1 HOT 1
- Request fails with NGHTTP2_PROTOCOL_ERROR for http2 requests HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http2-wrapper.