com.jimuwd.xian.registry-proxy 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +10 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -206,19 +206,22 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
206
206
|
else {
|
|
207
207
|
// write back to client
|
|
208
208
|
resToDownstreamClient.writeHead(upstreamResponse.status, safeHeaders);
|
|
209
|
-
//
|
|
209
|
+
// clean up when server if client is closed accidentally.
|
|
210
210
|
const cleanup = () => {
|
|
211
211
|
reqFromDownstreamClient.off('close', cleanup);
|
|
212
212
|
logger.warn(`Downstream client closed connection accidentally, stop pipe from upstream ${targetUrl} to downstream client.`);
|
|
213
213
|
upstreamResponse.body?.unpipe();
|
|
214
214
|
resToDownstreamClient.destroy();
|
|
215
|
+
reqFromDownstreamClient.destroy();
|
|
215
216
|
};
|
|
216
217
|
reqFromDownstreamClient.on('close', cleanup);
|
|
218
|
+
// clean up when server closes connection to downstream client.
|
|
217
219
|
const cleanup0 = () => {
|
|
218
220
|
resToDownstreamClient.off('close', cleanup0);
|
|
219
|
-
logger.info(`
|
|
220
|
-
upstreamResponse.body?.unpipe();
|
|
221
|
-
resToDownstreamClient.destroy();
|
|
221
|
+
logger.info(`Close connection to downstream client, destroy connection, upstream url is ${targetUrl}`);
|
|
222
|
+
/*upstreamResponse.body?.unpipe(); 代理服务器主动关闭与客户端的连接,不需要此时对接管道已经断开了,没必要重复断开*/
|
|
223
|
+
// resToDownstreamClient.destroy();
|
|
224
|
+
// reqFromDownstreamClient.destroy();
|
|
222
225
|
};
|
|
223
226
|
resToDownstreamClient.on('close', cleanup0);
|
|
224
227
|
// write back body data (chunked probably)
|
|
@@ -230,16 +233,15 @@ async function writeResponseToDownstreamClient(registryInfo, targetUrl, resToDow
|
|
|
230
233
|
logger.info(`Upstream server ${targetUrl} response.body ended.`);
|
|
231
234
|
resToDownstreamClient.end();
|
|
232
235
|
})
|
|
236
|
+
// connection will be closed automatically when all chunk data is transferred.
|
|
233
237
|
.on('close', () => {
|
|
234
|
-
|
|
235
|
-
logger.error(errMsg);
|
|
236
|
-
// resToDownstreamClient.destroy(new Error(errMsg));
|
|
237
|
-
resToDownstreamClient.destroy();
|
|
238
|
+
logger.info(`Upstream server ${targetUrl} closed connection.`);
|
|
238
239
|
})
|
|
239
240
|
.on('error', (err) => {
|
|
240
241
|
const errMsg = `Stream error: ${err.message}`;
|
|
241
242
|
logger.error(errMsg);
|
|
242
243
|
resToDownstreamClient.destroy(new Error(errMsg, { cause: err, }));
|
|
244
|
+
reqFromDownstreamClient.destroy(new Error(errMsg, { cause: err, }));
|
|
243
245
|
});
|
|
244
246
|
}
|
|
245
247
|
}
|