Last active
August 29, 2015 14:06
-
-
Save dwrensha/83d4dbafba9502646fbf to your computer and use it in GitHub Desktop.
detecting request cancellation in WebApp.rawConnectHandlers
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
/* | |
I start this in one terminal and in another I do `curl 127.0.0.1:3000` and immediately ctrl-C. | |
The output is: | |
$ meteor | |
[[[[[ ~/Desktop/raw_connect_handler_test ]]]]] | |
=> Started proxy. | |
=> Started MongoDB. | |
=> Started your app. | |
=> App running at: http://localhost:3000/ | |
I20140909-21:25:26.887(-4)? handling a request | |
I20140909-21:25:26.930(-4)? local port: 24116 | |
I20140909-21:27:26.832(-4)? CLOSE | |
Note here the "CLOSE" gets printed two minutes after I hit ctrl-C! It | |
seems that the 'close' event is not being emitted until the request times | |
out -- any EOF event is getting ignored somehow. | |
I expect instead for "CLOSE" to be printed as soon as I hit ctrl-C. | |
I also expect the local port to be 3000. I guess this means that Meteor is putting my | |
app behind some kind of proxy, and that proxy is failing to forward the 'close' event. | |
*/ | |
if (Meteor.isServer) { | |
Meteor.startup(function () { | |
WebApp.rawConnectHandlers.use(function (req, res, next) { | |
console.log("handling a request"); | |
console.log("local port: " + req.connection.localPort); | |
req.on('close', function() { | |
console.log("CLOSE"); | |
}); | |
}); | |
}); | |
} |
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 example works as I expect. | |
I start this in one terminal and in another I do `curl 127.0.0.1:7000` and immediately ctrl-C. | |
The output is: | |
$ node server.js | |
handling a request | |
local port: 7000 | |
CLOSE | |
where the "CLOSE" gets printed as soon as I hit ctrl-C. | |
*/ | |
var connect = require("connect"); | |
var http = require('http'); | |
var app = connect(); | |
app.use(function(req, res, next) { | |
console.log("handling a request"); | |
console.log("local port: " + req.connection.localPort); | |
req.on("close", function() { | |
console.log("CLOSE"); | |
}); | |
}); | |
var httpServer = http.createServer(app); | |
httpServer.listen(7000); | |
The root problem is a bug with older versions of http-proxy. Meteor uses version 1.0.2, but cancellation of requests is not handled until version 1.1.2:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My question: how can I detect cancelled requests when using WebApp.rawConnectHandlers? It appears to me that the 'close' event does not get fired on EOF.