-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix server side close unexpected exit closes #541
- Loading branch information
Showing
8 changed files
with
134 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { fetch, setGlobalDispatcher, Agent } = require('..'); | ||
|
||
setGlobalDispatcher(new Agent({ | ||
allowH2: true, | ||
})); | ||
|
||
async function main() { | ||
for (let i = 0; i < 100; i++) { | ||
try { | ||
const r = await fetch('https://edgeupdates.microsoft.com/api/products'); | ||
console.log(r.status, r.headers, (await r.text()).length); | ||
} catch (err) { | ||
// console.error(err); | ||
// throw err; | ||
if (err.code === 'UND_ERR_SOCKET') { | ||
continue; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
|
||
main().then(() => { | ||
console.log('main end'); | ||
}).catch(err => { | ||
console.error('main error throw: %s', err); | ||
// console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
process.on('beforeExit', (...args) => { | ||
console.error('beforeExit', args); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { request, Agent, setGlobalDispatcher } = require('undici'); | ||
|
||
setGlobalDispatcher(new Agent({ | ||
allowH2: true, | ||
})); | ||
|
||
async function main() { | ||
for (let i = 0; i < 100; i++) { | ||
try { | ||
const r = await request('https://edgeupdates.microsoft.com/api/products'); | ||
console.log(r.statusCode, r.headers, (await r.body.blob()).size); | ||
} catch (err) { | ||
// console.error(err); | ||
// throw err; | ||
if (err.code === 'UND_ERR_SOCKET') { | ||
continue; | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
|
||
main().then(() => { | ||
console.log('main end'); | ||
}).catch(err => { | ||
console.error('main error throw: %s', err); | ||
// console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
process.on('beforeExit', (...args) => { | ||
console.error('beforeExit', args); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const { HttpClient } = require('..'); | ||
|
||
const httpClient = new HttpClient({ | ||
allowH2: true, | ||
}); | ||
|
||
async function main() { | ||
for (let i = 0; i < 1000000; i++) { | ||
// await httpClient.request('https://registry.npmmirror.com/'); | ||
// console.log(r.status, r.headers, r.res.timing); | ||
try { | ||
const r = await httpClient.request('https://edgeupdates.microsoft.com/api/products'); | ||
// console.log(r.status, r.headers, r.data.length, r.res.timing); | ||
if (i % 10 === 0) { | ||
// console.log(r.status, r.headers, r.data.length, r.res.timing); | ||
console.log(i, r.status, process.memoryUsage()); | ||
} | ||
} catch (err) { | ||
console.error('%s error: %s', i, err.message); | ||
} | ||
} | ||
} | ||
|
||
main().then(() => { | ||
console.log('main end'); | ||
}).catch(err => { | ||
console.error('main error throw: %s', err); | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
|
||
// process.on('uncaughtException', (...args) => { | ||
// console.error('uncaughtException', args); | ||
// process.exit(1); | ||
// }); | ||
|
||
// process.on('unhandledRejection', (...args) => { | ||
// console.error('unhandledRejection', args); | ||
// process.exit(2); | ||
// }); | ||
|
||
// process.on('uncaughtExceptionMonitor', (...args) => { | ||
// console.error('uncaughtExceptionMonitor', args); | ||
// process.exit(2); | ||
// }); | ||
|
||
process.on('beforeExit', (...args) => { | ||
console.error('beforeExit', args); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters