[SERVER-33351] remove try/catch in background job Created: 15/Feb/18  Updated: 29/Oct/23  Resolved: 18/Dec/18

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.1.7

Type: Bug Priority: Major - P3
Reporter: Eric Milkie Assignee: Gabriel Russell (Inactive)
Resolution: Fixed Votes: 0
Labels: former-quick-wins, neweng, service_architecture
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Dev Tools 2018-12-03, Dev Tools 2018-12-17, Dev Tools 2018-12-31
Participants:
Linked BF Score: 0

 Description   

BackgroundJob::jobBody() has this code:

    try {
        run();
    } catch (const std::exception& e) {
        error() << "backgroundjob " << threadName << " exception: " << redact(e.what());
        throw;
    }

The problem with this is that the rethrow will always trigger std::terminate(), since there are no further exception handlers up the stack. The catch-and-rethrow here will make the resulting stack trace appear from the point of rethrow instead of at the point of the original throw, making the stack trace useless for debugging. If we removed this try/catch, the stack trace would become useful again. Note that our terminate handler already successfully logs e.what(), so no functionality will be lost.



 Comments   
Comment by Githook User [ 13/Dec/18 ]

Author:

{'username': 'gabrielrussell', 'email': 'gabriel.russell@mongodb.com', 'name': 'Gabriel Russell'}

Message: SERVER-33351 perserve stack in BackgroundJob exceptions
Branch: master
https://github.com/mongodb/mongo/commit/ca80f766ffc4f82beb46e7b13132afc0c555d4aa

Generated at Thu Feb 08 04:33:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.