Join GitHub today
API occasionally sends a malformed query and Mongo closes connection #246
This issue appears occasionally in an API production environment used by Publish
MongoDB log reports an error and the database closes the connection, causing a sequence of API errors and data loss
The error reported by MongoDB is:
Being a live environment, it is difficult to trace which query creates this issue, but it has been seen after PUT or DELETE requests.
Probably the first step would be to introduce verbose logging (with the full content of the request sent to the database) in order to gather more info
I managed to trace the offending query, which is probably sent by a badly written hook, yet to be identified
It's a simple empty _id:
If I try to hit API with a similar query, it does not generate the MongoDB error
Maybe there is some validation, which doesn't happen when the query is sent directly from the model?
The error originates from a hook that passes API a query containing an ObjectID. API attempts to make this case insensitive and it looks as if a case insensitive ObjectID = "".... The hook can be changed to pass a string in the query instead, as a temporary fix.
Two pieces of work: