Skip to content

Instantiate multiple instances of resource clients when a closure repeatedly accesses the same resource object #136

Open

Description

@jianzs

In the current deduction system, multiple accesses to the same resource object within a closure do not result in reduced dependencies. This leads to attempts at creating several clients for the identical resource object, resulting in more than one variable with the same name.

Take this as an example: we call both invoke and endpointUrl methods of a single sagemaker object within one router handler. The deducer identifies two dependencies related to this sagemaker object for the router handler's corresponding compute closure. One is classified as a client API dependency while the other is seen as a captured property dependency. When extracting this closure into a separate directory, it's necessary for our deducer to create a sagemaker client. Ideally, only one such client should be created; however, currently two identical ones are being generated instead. This causes exceptions during runtime on cloud platforms.

router.post("/generate", async (req) => {
  console.log("the endpoint url of the sagemaker model is", sagemaker.endpointUrl());

  const payload = req.body;
  if (!payload) {
    return {
      statusCode: 400,
      body: "The request body is empty. Please provide a valid input.",
    };
  }

  const data = JSON.parse(payload);
  if (!data["inputs"]) {
    // The payload should be a JSON object with a key "inputs".
    return {
      statusCode: 400,
      body: "The request body is invalid. Please provide a valid input.",
    };
  }

  // Invoke the SageMaker endpoint with the input data and return the response to the users.
  const output = await sagemaker.invoke(data);
  return {
    statusCode: 200,
    body: JSON.stringify(output),
  };
});

Activity

  1. added
    bug
    deducer
    on Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdeducer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions