iriscouch / follow

Very stable, very reliable, NodeJS CouchDB _changes follower
Apache License 2.0
393 stars 82 forks source link

Error when db is deleted/recreated #6

Closed fabien closed 12 years ago

fabien commented 12 years ago

Currently Follow will stop if the db being followed is deleted, or recreated:

Change has no .seq field: {"last_seq":7}

This could be problematic but I guess Follow should be aware of such situations and restart the process without raising an exception (or perhaps make this configurable).

jhs commented 12 years ago

Definitely. Thanks for noticing the bug!

I just encountered my own bug today so I will roll both of these into a new test suite.

jhs commented 12 years ago

Okay, I finally realized that this is an error event. Perhaps Follow could keep pinging the database without throwing an error, but there are two problems with that:

  1. The database might never come back. You could catch that with the inactivity_ms setting, but then there's no way to distinguish between an idle database and a deleted database.
  2. Even if the database was re-created, its new sequence numbers would be totally unrelated to the ones you'd been receiving and working with.

So a database deletion falls under the "your application might be in trouble" category. Now it actually detects that situation and returns a meaningful error instead of the old "I have no idea what just happened" error.

Thanks again for the bug report! This one was fun.

fabien commented 12 years ago

Thanks for looking into it! In the end it makes the most sense to mark it as an error, indeed.

jhs commented 12 years ago

You're welcome. Note, I have not added to the documentation, but you can check the error object for .deleted or .last_seq to identify this type of failure.