Created
December 14, 2018 23:08
-
-
Save jish/60ba346a2ce145bbdef30f666f2f763a to your computer and use it in GitHub Desktop.
Express timeout
This file contains hidden or 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
$ time curl -i "http://localhost:3000/never" | |
HTTP/1.1 503 Service Unavailable | |
X-Powered-By: Express | |
Content-Security-Policy: default-src 'self' | |
X-Content-Type-Options: nosniff | |
Content-Type: text/html; charset=utf-8 | |
Content-Length: 704 | |
Date: Fri, 14 Dec 2018 23:04:13 GMT | |
Connection: keep-alive | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Error</title> | |
</head> | |
<body> | |
<pre>ServiceUnavailableError: Response timeout<br> at IncomingMessage.<anonymous> (/Users/josh/code/ecmascript/express_timeout/node_modules/connect-timeout/index.js:84:8)<br> at emitOne (events.js:116:13)<br> at IncomingMessage.emit (events.js:211:7)<br> at Timeout._onTimeout (/Users/josh/code/ecmascript/express_timeout/node_modules/connect-timeout/index.js:49:11)<br> at ontimeout (timers.js:482:11)<br> at tryOnTimeout (timers.js:317:5)<br> at Timer.listOnTimeout (timers.js:277:5)</pre> | |
</body> | |
</html> | |
curl -i "http://localhost:3000/never" 0.01s user 0.01s system 0% cpu 2.033 total |
This file contains hidden or 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
var express = require("express"); | |
var connectTimeout = require("connect-timeout"); | |
var app = express(); | |
app.use(connectTimeout(2000)); | |
app.get("/never", function(req, res) { | |
res.status(200); | |
// never call `res.send("foo")` or `res.json({ bar: "baz" })` | |
}); | |
app.listen(3000); |
This file contains hidden or 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
$ npm i -P express connect-timeout | |
+ [email protected] | |
+ [email protected] | |
updated 2 packages in 0.885s | |
$ node server.js | |
ServiceUnavailableError: Response timeout | |
at IncomingMessage.<anonymous> (/Users/josh/code/ecmascript/express_timeout/node_modules/connect-timeout/index.js:84:8) | |
at emitOne (events.js:116:13) | |
at IncomingMessage.emit (events.js:211:7) | |
at Timeout._onTimeout (/Users/josh/code/ecmascript/express_timeout/node_modules/connect-timeout/index.js:49:11) | |
at ontimeout (timers.js:482:11) | |
at tryOnTimeout (timers.js:317:5) | |
at Timer.listOnTimeout (timers.js:277:5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment