[SERVER-49874] Make the server to be able to run JavaScript functions with ThreadSanitizer instrumentation (TSAN) Created: 24/Jul/20  Updated: 29/Oct/23  Resolved: 17/Aug/20

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 4.7.0

Type: Task Priority: Major - P3
Reporter: Mindaugas Malinauskas Assignee: Mindaugas Malinauskas
Resolution: Fixed Votes: 0
Labels: qexec-team, thread-sanitizer
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Sprint: Query 2020-08-24
Participants:
Linked BF Score: 31

 Description   

Problem

When the server is built with the ThreadSanitizer instrumentation (TSAN) (build variant: “~ TSAN Enterprise Ubuntu 20.04 DEBUG (Biggie)”) execution of JavaScript functions fails with the exception below.

{"code":139,"codeName":"JSInterpreterFailure","errmsg":"InternalError: too much recursion"}

An example of the test that fails under TSAN is jstests/core/mr_sort.js.

The stack size for MozJS JavaScript engine execution is decided at https://github.com/mongodb/mongo/blob/master/src/mongo/scripting/mozjs/implscope.cpp#L378. For TSAN builds the stack size in a relevant test is around 180000 bytes, and for a regular build - around 950000 bytes, due to a memory overhead of TSAN instrumentation. 200kB of free stack space appears to be not enough to run JavaScript functions.

Potential solutions

  • Increase stack sizes for ThreadSanitizer instrumented builds.
    • On client connected worker threads, one could add TSAN specific customization to launchServiceWorkerThread to increase the stack sizes when using TSAN. If it is on the thread owned by the ProxyScope it will be harder because it uses a std::thread, and we don’t have control over the stack sizes for those.


 Comments   
Comment by Githook User [ 17/Aug/20 ]

Author:

{'name': 'Mindaugas Malinauskas', 'email': 'mindaugas.malinauskas@mongodb.com'}

Message: SERVER-49874 Make the server to be able to run JavaScript functions with ThreadSanitizer instrumentation (TSAN)
Branch: master
https://github.com/mongodb/mongo/commit/8fe87db3b12f2e9fd4b68d9fcb33bff8b9d68d9a

Generated at Thu Feb 08 05:21:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.