Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-102103

Incorrect error code is returned from mozjs when out of memory is encountered

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.2.0-rc0
    • 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.

            Assignee:
            santiago.roche@mongodb.com Santiago Roche
            Reporter:
            santiago.roche@mongodb.com Santiago Roche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: