Suddenly getting "MongoError: JsFunction is unavailable" errors

As of some time this morning our client applications suddenly started getting “JsFunction is unavailable” error responses from the MongoDB server on queries using $where clauses. Googling for this error yielded 0 results so I starting looking into the MongoDB server code myself. It seems that this error is generated from here: https://github.com/mongodb/mongo/blob/master/src/mongo/db/matcher/expression_where.h#L81 and could only happen when the server is in some weird state where jsFunction, which seems to be the library used to interpret Javascript in queries, is not properly initialized somehow. However there has been no update, configuration change or even a failover or server restart around that time, and manually restarting the leader node (thereby causing a failover) doesn’t fix the problem.

Did anyone ever encounter this? Any tips on how to solve it?