Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-56233

Cleanup resources left behind from failed operations

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Minor
    • None
    • None
    • js-evaluator
    • 0

    Description

      When an operation fails, we log the error and return it to the user. However, these operations may have created some resources before they failed. In the current design, these resources are not cleaned up before returning the error.

      This can cause unusable resources to live on in the JS Evaluator, occupying system resources unnecessarily.

      Say, for example while creating a worker (which can be understood as a combination of the driver thread, GC thread and a V8 isolate), let's say the driver thread and GC thread creation was successful but, the V8 isolate creation failed then the two successfully created threads would live on, even though the operation of creating a worker failed. Ideally, these threads should be terminated before returning.

       

      The suggestion/improvement is to make these operations transactional, such that if a step of an operation fails, then any resources created as part of the sequence of steps, such as thread, file descriptors, objects etc. are all cleared up before returning with an error from the function. This would ensure that the execution environment remains clean, and no unusable resources are created.

      Extending on the idea of transactions, one suggestion could be to use an approach like Saga transactions so that if any step of an operation fails, then any resources created from the previous (successful) steps, are cleaned up before returning from the function.

       

      For example:

      If we have a function `f`, which has 3 steps that each create a resource A, B and C, then using the transactional idea, we expect the following behaviour in the below 2 cases.

      Case-1

      func f(){
        A ✅  // Resource is created locally
        B ❌   return err
        // As resource A is local, it will get cleared once we exit this scope
      } 

       

      Case-2

      func f() {   
        A ✅ // Resource is created locally   
        B ✅ // Resource is created locally   
        C ✅ // Resource is created locally   
        A = persistent(A)   
        B = persistent(B)   
        C = persistent(C)   
        // As resources A, B and C have been made persistent, they will persist. beyond the scope of this function
        return 
      } 

       

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            rishit.chaudhary Rishit Chaudhary
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty