Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: felixge/node-formidable
base: v0.9.3
...
head fork: felixge/node-formidable
compare: v0.9.4
  • 2 commits
  • 3 files changed
  • 2 commit comments
  • 1 contributor
Commits on Jun 29, 2010
@felixge Fix: Handle pause() calls on destroyed uploads
This patch also improves the behavior for resume().

net.Stream currently does not guarantee 'data' to stop emitting after
pausing a stream. This makes the current throttling function
problematic and prone to race conditions. This patch will take of it
for now, but a further patch for node itself will make things even
smoother.
3988f82
@felixge Bump version 857559e
View
17 lib/formidable/incoming_form.js
@@ -31,7 +31,16 @@ exports.IncomingForm = IncomingForm;
IncomingForm.prototype.parse = function(req, cb) {
this.pause = function() {
- req.pause();
+ try {
+ req.pause();
+ } catch (err) {
+ // the stream was destroyed
+ if (!this.ended) {
+ // before it was completed, crash & burn
+ this._error(err);
+ }
+ return false;
+ }
return true;
};
@@ -39,7 +48,11 @@ IncomingForm.prototype.parse = function(req, cb) {
try {
req.resume();
} catch (err) {
- this._error(err);
+ // the stream was destroyed
+ if (!this.ended) {
+ // before it was completed, crash & burn
+ this._error(err);
+ }
return false;
}
View
2  package.json
@@ -1,5 +1,5 @@
{ "name" : "formidable"
-, "version": "0.9.3"
+, "version": "0.9.4"
, "dependencies": {"gently": ">=0.7.0"}
, "directories" : { "lib" : "./lib/formidable" }
, "main" : "./lib/formidable/index"
View
43 test/simple/test-incoming-form.js
@@ -58,13 +58,41 @@ test(function parse() {
gently.expect(REQ, 'pause');
assert.strictEqual(form.pause(), true);
})();
-
+
+ (function testPauseCriticalException() {
+ form.ended = false;
+
+ var ERR = new Error('dasdsa');
+ gently.expect(REQ, 'pause', function() {
+ throw ERR;
+ });
+
+ gently.expect(form, '_error', function(err) {
+ assert.strictEqual(err, ERR);
+ });
+
+ assert.strictEqual(form.pause(), false);
+ })();
+
+ (function testPauseHarmlessException() {
+ form.ended = true;
+
+ var ERR = new Error('dasdsa');
+ gently.expect(REQ, 'pause', function() {
+ throw ERR;
+ });
+
+ assert.strictEqual(form.pause(), false);
+ })();
+
(function testResume() {
gently.expect(REQ, 'resume');
assert.strictEqual(form.resume(), true);
})();
- (function testResumeException() {
+ (function testResumeCriticalException() {
+ form.ended = false;
+
var ERR = new Error('dasdsa');
gently.expect(REQ, 'resume', function() {
throw ERR;
@@ -76,6 +104,17 @@ test(function parse() {
assert.strictEqual(form.resume(), false);
})();
+
+ (function testResumeHarmlessException() {
+ form.ended = true;
+
+ var ERR = new Error('dasdsa');
+ gently.expect(REQ, 'resume', function() {
+ throw ERR;
+ });
+
+ assert.strictEqual(form.resume(), false);
+ })();
(function testEmitError() {
var ERR = new Error('something bad happened');

Showing you all comments on commits in this comparison.

@tj

cool that seems to have done the trick :D thanks man, great lib

@felixge
Owner

np, let me know if you find anything else : )

Something went wrong with that request. Please try again.