-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Integration
-
Fully Compatible
-
ALL
-
200
https://jira.mongodb.org/browse/BF-36828 identified an edge case where, when an OOM is encountered within mozjs, the incorrect error code is returned.
Typically, SpiderMonkey does not throw exceptions. Instead, the pattern is that all calls to the JSAPIs return either true/false, and if such a call returns false, the JSContext msut be checked for pending exceptions.
This is generally achieved via MozJSImplScope::_checkErrorState. However, this does not cover all scenarios in which we could have an OOM exception. For example, ObjectWrapper makes use of throwCurrentJSException to propagate any pending exception, calling throwCurrentJSException at the end of each of its public methods which use JS internals.
It's possible that we may encounter an OOM within mozjs when using ObjectWrapper. Calling throwCurrentJSException in such cases results in the SpiderMonkey OOM exception that was set on the JSContext being propagated out to mongod, with the incorrect error code (i.e InternalError) and error message.
Instead, we should check for the out of memory condition to ensure we return the expected error code and error message.