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

JS UDF: If a javascript function contains a transaction, and you also set tximplicit(or run as tx in UI), you get a panic

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 7.1.0
    • 7.1.0
    • query
    • Untriaged
    • 1
    • Unknown

    Description

      \set -tximplicit true;
      EXECUTE FUNCTION doPayment(1,6,2873.55,1,6,"501","None","2022-01-10 11:07:34.823485"); 

      "errors": [         {             "code": 10109,             "msg": "Error executing function doPayment (delivery:doPayment): Evaluator error Exceptions from JS code : run doPayment failed:\nException: Error: Transaction fetch error - cause: TxGet() Panic: runtime error: invalid memory address or nil pointer dereference\nLocation: functions/delivery.js:46 \nCode:         query1 = N1QL('EXECUTE PAYMENT_getWarehouse',params);\nError\n    at doPayment (functions/delivery.js:46:18)\n - cause: Evaluator error Exceptions from JS code : run doPayment failed:\nException: Error: Transaction fetch error - cause: TxGet() Panic: runtime error: invalid memory address or nil pointer dereference\nLocation: functions/delivery.js:46 \nCode:         query1 = N1QL('EXECUTE PAYMENT_getWarehouse',params);\nError\n    at doPayment (functions/delivery.js:46:18)\n"
      

      This also only happens, if the begin and commit are being executed as prepared statements

      e.g.

      function doPayment(w_id,d_id,h_amount,c_w_id,c_d_id,c_id,c_last,h_date){
       
       
             var query1 = N1QL('EXECUTE PAYMENT_beginWork');
             query1.close();
       
              params = [w_id];
              query1 = N1QL('EXECUTE PAYMENT_getWarehouse',params);
              var warehouse = [];
              for (const row of query1) {
                   warehouse.push(row);
              }
              query1.close();
      params = [w_id, d_id];
              query1 = N1QL('EXECUTE PAYMENT_getDistrict',params);
              var district = [];
              for (const row of query1) {
                   district.push(row);
              }
              query1.close();
       
       
              var query1 = N1QL('EXECUTE PAYMENT_commitWork');
              
              query1.close();
              return [ warehouse, district];
          } 

      If you instead replace by:

      function doPayment(w_id,d_id,h_amount,c_w_id,c_d_id,c_id,c_last,h_date){
       
       
             var query1 = N1QL('BEGIN WORK');
              query1.close();
       
       
       
       
              params = [w_id];
              query1 = N1QL('EXECUTE PAYMENT_getWarehouse',params);
              var warehouse = [];
              for (const row of query1) {
                   warehouse.push(row);
              }
              query1.close();
      params = [w_id, d_id];
              query1 = N1QL('EXECUTE PAYMENT_getDistrict',params);
              var district = [];
              for (const row of query1) {
                   district.push(row);
              }
              query1.close();
       
       
       
              var query1=N1QL('COMMIT WORK');
              query1.close();
       
              return [ warehouse, district];
          } 

      it works as designed:

       

      errors": [
              {
                  "code": 10109,
                  "msg": "Error executing function doPayment (delivery:doPayment): Evaluator error Exceptions from JS code : run doPayment failed:\nException: Error: START_TRANSACTION statement is not supported within the transaction\nLocation: functions/delivery.js:4 \nCode:        var query1 = N1QL('BEGIN WORK');\nError\n    at doPayment (functions/delivery.js:4:21)\n - cause: Evaluator error Exceptions from JS code : run doPayment failed:\nException: Error: START_TRANSACTION statement is not supported within the transaction\nLocation: functions/delivery.js:4 \nCode:        var query1 = N1QL('BEGIN WORK');\nError\n    at doPayment (functions/delivery.js:4:21)\n"
              }
      

       

       

      Attachments

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

        Activity

          People

            kamini.jagtiani Kamini Jagtiani
            kamini.jagtiani Kamini Jagtiani
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty