googleapis / nodejs-kms

This repository is deprecated. All of its content and history has been moved to googleapis/google-cloud-node.
https://cloud.google.com/kms/
Apache License 2.0
57 stars 25 forks source link

main error GoogleError: Total timeout of API google.cloud.kms.v1.KeyManagementService exceeded 60000 milliseconds before any response was received. #515

Closed sskanishk closed 1 year ago

sskanishk commented 2 years ago

📦 Need Help I'm passing an array of objects in cloud function which has symmetric encryption in place to encrypt the mobile field of an array of objects. I'm getting timeout, is there anything I'm missing or any other approach to do the task. Please let me know thanks

Environment details

Steps to reproduce

  1. Create GCP cloud function and add code snippet to encrypt ( google_symmetric_key )
  2. Hit cloud function API with payload array of object.
  3. Length of the array is 10K
  4. I Want to encrypt the mobile field.

    Example

    let payload = [
    { abc: xyz, mobile: "9600096000" },
    { abc: xyz1, mobile: "9600096001" },
    .....
    ]
sofisl commented 2 years ago

@sskanishk, can you provide the code in your cloud function?

sskanishk commented 2 years ago

yes @sofisl

// input = array of object [ maximum array length would 10k+ ]
async function encrypt_aes(input, key, fields) {
  try {
    if(Array.isArray(input)) {
      return Promise.all(input.map((obj) => {
        if(typeof obj === 'object') {
          return _encryptObject(obj, key, fields)
        }
      }))
    }
  } catch (error) {
    console.log(error)
  } 
}

// fields = ['mobile']
async function _encryptObject(input, key, fields) {
  if(fields.length > 0) {
    for (const field of fields) { 
      if(input[field].length < 15 && field === "mobile") {
        input[field] = await _encryptSymmetric(key, input[field])
      }   
    }
  }
  return input
}

// _encryptSymmetric
async _encryptSymmetric() { ... https://cloud.google.com/kms/docs/encrypt-decrypt#encrypt  }
tmatsuo commented 2 years ago

I think you can add a callOption to a specific API call, something like this:

await client.encrypt({
    name: keyName,
    plaintext: plaintextBuffer,
    plaintextCrc32c: {
      value: plaintextCrc32c,
    },
  }, {timeout: 120000}); // Doubling the timeout
sofisl commented 1 year ago

Hello! We are moving this repo to googleapis/google-cloud-node, and are closing any stale issues. If this issue is persisting for you, we kindly ask that you reopen in that repo. Thank you very much!