Skip to content

Commit

Permalink
agent pool
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect committed Jan 24, 2024
1 parent 8211ddc commit 12b455c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
107 changes: 54 additions & 53 deletions src/context/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2090,8 +2090,6 @@ class ZitiContext extends EventEmitter {

let ret;

try {

let fetchPromise = new Promise( async (resolve, reject) => {

/**
Expand All @@ -2113,59 +2111,66 @@ class ZitiContext extends EventEmitter {

let req;

if (options.method === 'GET') {

req = http.get(options);
req.agent = await this.getZitiAgentPool().connect(req, options);

} else {
try {

req = http.request(options);
req.agent = await this.getZitiAgentPool().connect(req, options);
if (options.method === 'GET') {

req = http.get(options);
req.agent = await this.getZitiAgentPool().connect(req, options);

} else {

if (options.body) {
if (options.body instanceof Promise) {
let chunk = await options.body;
req.write( chunk );
}
else if (options.body instanceof ZitiFormData) {

let p = new Promise((resolve, reject) => {

let stream = options.body.getStream();

stream.on('error', err => {
reject(new Error(`${err.message}`));
});

stream.on('end', () => {
try {
resolve();
} catch (err) {
req = http.request(options);
req.agent = await this.getZitiAgentPool().connect(req, options);

if (options.body) {
if (options.body instanceof Promise) {
let chunk = await options.body;
req.write( chunk );
}
else if (options.body instanceof ZitiFormData) {

let p = new Promise((resolve, reject) => {

let stream = options.body.getStream();

stream.on('error', err => {
reject(new Error(`${err.message}`));
}
});

stream.on('end', () => {
try {
resolve();
} catch (err) {
reject(new Error(`${err.message}`));
}
});

stream.pipe(new BrowserStdout({req: req}))
});

stream.pipe(new BrowserStdout({req: req}))
});

await p;

}
else {
let buffer;
if (options.body.arrayBuffer) {
let ab = await options.body.arrayBuffer();
buffer = new Buffer(ab)
} else {
buffer = options.body;

await p;

}
else {
let buffer;
if (options.body.arrayBuffer) {
let ab = await options.body.arrayBuffer();
buffer = new Buffer(ab)
} else {
buffer = options.body;
}
req.end( buffer );
}
req.end( buffer );
} else {
req.end();
}
} else {
req.end();

}

}
catch (error) {
let errResponse = new Response(new Blob(), { status: 400, statusText: `ZBR Error: ${error}` });
resolve(errResponse);
}

req.on('error', err => {
Expand All @@ -2175,7 +2180,7 @@ class ZitiContext extends EventEmitter {

req.on('response', async res => {

self.logger.debug(`httpFetch on.reponse() elapsed[${et.getValue()}] url[${url}]`);
self.logger.debug(`httpFetch on.response() elapsed[${et.getValue()}] url[${url}]`);

const response_options = {
url: url,
Expand Down Expand Up @@ -2240,10 +2245,6 @@ class ZitiContext extends EventEmitter {
});

ret = await fetchPromise;

} finally {
// release();
}

return ret;
}
Expand Down
1 change: 0 additions & 1 deletion src/http/ziti-agent-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ class ZitiAgentPool extends EventEmitter {
tid = setTimeout(() => {
this.logger.trace('ending zitiAgent due to timeout')
timeoutHit = true
// force kill the node driver, and let libpq do its teardown
zitiAgent.connection ? zitiAgent.connection.stream.destroy() : zitiAgent.end()
}, this.options.connectionTimeoutMillis)
}
Expand Down

0 comments on commit 12b455c

Please sign in to comment.