[SERVER-5842] Exceptions thrown in scripting/engine_spidermonkey.cpp need to be handled there Created: 14/May/12 Updated: 03/Jan/18 Resolved: 30/May/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | None |
| Fix Version/s: | 2.1.2 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Tad Marshall | Assignee: | Tad Marshall |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||||||||||||||||||||||
| Description |
|
There are a few cases where a "native" JavaScript function implemented in scripting/engine_spidermonkey.cpp or scripting/sm_db.cpp will throw an exception. An example (currently) is the native_print() function which calls Convertor::toString() which can throw an exception. If this exception isn't caught before control passes out through SpiderMonkey then SpiderMonkey is left in a corrupted state and attempts to use JavaScript after this, even to display the shell's prompt, will generate access violations (segfaults). We need to use try/catch around any exceptions that can be thrown within engine_spidermonkey.cpp and return normally (usually with JS_FALSE) so that SpiderMonkey can maintain its state properly. |
| Comments |
| Comment by auto [ 31/May/12 ] |
|
Author: {u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: The native_helper() routine in engine_spidermonkey.cpp calls |
| Comment by auto [ 30/May/12 ] |
|
Author: {u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: For selected functions, catch SocketExceptions and pass them |
| Comment by auto [ 30/May/12 ] |
|
Author: {u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: In every routine called by SpiderMonkey, use try/catch to grab all |
| Comment by auto [ 27/May/12 ] |
|
Author: {u'login': u'tadmarshall', u'name': u'Tad Marshall', u'email': u'tad@10gen.com'}Message: Code cleanup prior to fixing Make three injected native JavaScript routines static since they are |
| Comment by Tad Marshall [ 22/May/12 ] |
|
After researching JavaScript exceptions in the SpiderMonkey code and online (Mozilla) documentation I learned that the JS_ReportError() function that we call from some places actually creates a JavaScript exception that can be caught with a JavaScript try/catch. This seems like the right way to handle all errors in JavaScript that are not fatal MongoDB conditions. Incorrect use of (for example) BSON objects created in JavaScript should be handled by sending a JavaScript exception to the code that caused it (by using JS_ReportError()) and should not be treated as MongoDB exceptions. Following this approach throughout engine_spidermonkey.cpp and sm_db.cpp should eliminate the crashing problems we've seen following JavaScript failures. |
| Comment by Tad Marshall [ 18/May/12 ] |
|
Moving from 2.3.0 to 2.1.2 because I resolved |