Permalink
Browse files

Fix a bug with ZOMBIE QUERIES! 💀

The streaming event get endpoint wasn't correctly terminating the query callback
when the connection is closed, so it would continue polling forever.
  • Loading branch information...
1 parent eee5486 commit 408a979a6b6ea0926bb709ea0c0e5ff0de256349 @mbostock mbostock committed Apr 17, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/cube/event.js
View
@@ -136,11 +136,15 @@ exports.getter = function(db) {
// If the callback is closed (for example, when the WebSocket is
// closed, or when the maximum number of events from the GET endpoint
- // is reached), treat this event as the last event.
- if (callback.closed) cursor.close(), event = null;
+ // is reached), treat this event as the last event. Note that closing
+ // the cursor mid-loop causes an error, which we ignore!
+ if (callback.closed) {
+ cursor.close();
+ if (!stream) callback(null);
+ return;
+ }
- // Closing the cursor mid-loop causes an error, which we then ignore.
- else handle(error);
+ handle(error);
// A null event indicates that there are no more results. For
// streaming queries, we don't report this sentinel value, and instead

0 comments on commit 408a979

Please sign in to comment.