Cloud function infinite recursion detection method, device, equipment and storage medium

By performing recursion detection and resource monitoring before cloud functions run, the problem of huge bills caused by infinite recursion of cloud functions is solved, and safe and efficient resource management is achieved.

CN117130911BActive Publication Date: 2026-04-21CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER
Filing Date
2023-08-08
Publication Date
2026-04-21

AI Technical Summary

Technical Problem

The scalability and pay-as-you-go nature of cloud functions can lead to huge bills in cases of infinite recursion, and the lack of effective automated limiting mechanisms can impose unexpected burdens on users.

Method used

Before running cloud functions, recursion detection is performed. By detecting function call parameters and call chains, the risk of infinite recursion is identified, and restrictions are imposed when resource consumption exceeds normal levels, including the number of concurrent users and CPU utilization.

Benefits of technology

It effectively avoids infinite recursion of cloud functions, reduces resource waste and huge bills, and provides a dual detection mechanism to ensure the safe operation of cloud functions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117130911B_ABST
    Figure CN117130911B_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, device, and storage medium for detecting infinite recursion in cloud functions. The method includes: before running a user-uploaded first cloud function, performing a recursion check on the code of the first cloud function to determine if infinite recursion exists; if the recursion check determines that the first cloud function does not have infinite recursion, then allowing the first cloud function to run; and during the running of the first cloud function, monitoring its resource usage; and if the resource usage of the first cloud function meets abnormal resource consumption conditions, restricting its resource usage. This method can prevent infinite recursion in cloud functions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of cloud computing technology, and in particular to a method, apparatus, device, and storage medium for detecting infinite recursion of cloud functions. Background Technology

[0002] With the development of cloud computing technology, cloud functions, with their advantages of rapid deployment, elastic scaling, lightweight and low cost, and high resource utilization, have gradually become the main way of cloud computing applications. Users only need to write code and define triggering events according to the specifications to use cloud functions. They do not need to worry about how the code runs and scales, because the specific runtime environment and elastic scaling of cloud functions are maintained by cloud service providers, who bill based on the resource usage of cloud functions during runtime.

[0003] However, precisely because cloud functions are extremely easy to expand and are billed based on resource usage, if a cloud function becomes infinitely recursive, its lightweight and infinitely scalable nature can easily lead to huge bills and impose unexpected burdens on users. Therefore, how to avoid infinite recursion in cloud functions has become an urgent problem to be solved. Summary of the Invention

[0004] This application provides a method, apparatus, device, and storage medium for detecting infinite recursion of cloud functions, which can prevent infinite recursion of cloud functions.

[0005] In a first aspect, this application provides a method for detecting infinite recursion in cloud functions. The method includes: performing recursion detection on the code of the first cloud function before running the user-uploaded first cloud function to determine whether the first cloud function has infinite recursion; if the recursion detection determines that the first cloud function does not have infinite recursion, then allowing the first cloud function to run, and during the running of the first cloud function, monitoring the resource usage of the first cloud function, and if the resource usage of the first cloud function meets the abnormal resource consumption condition, restricting the resource usage of the first cloud function.

[0006] In one embodiment, recursion detection is performed on the code of the first cloud function to determine whether the first cloud function has infinite recursion. This includes: based on the code of the first cloud function, detecting the call parameters of each function included in the first cloud function to obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, detecting whether other cloud functions called by the first cloud function call back to the first cloud function to obtain a second recursion detection result; and determining whether the first cloud function has infinite recursion based on the second recursion detection result.

[0007] In one embodiment, the call parameters include the number of call stack levels. Detecting the call parameters of each function included in the first cloud function to obtain a first recursion detection result includes: detecting whether the number of call stack levels of each function included in the first cloud function exceeds a preset threshold; if it exceeds the preset threshold, then determining that the first recursion detection result indicates that the first cloud function has infinite recursion; if it does not exceed the preset threshold, then determining that the first recursion detection result indicates that the first cloud function does not have infinite recursion.

[0008] In one embodiment, detecting whether other cloud functions called by the first cloud function call back the first cloud function to obtain a second recursive detection result includes: obtaining the cloud function call chain of the first cloud function, wherein the first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function; determining whether each cloud function in the cloud function call chain calls back the first cloud function to obtain the second recursive detection result.

[0009] In one embodiment, determining whether the first cloud function has infinite recursion based on the second recursion detection result includes: if the second recursion detection result indicates that other cloud functions called by the first cloud function call back the first cloud function, outputting a prompt message to the user, and determining whether the first cloud function has infinite recursion based on the indication information provided by the user based on the prompt message; if the second recursion detection result indicates that other cloud functions called by the first cloud function do not call back the first cloud function, then determining that the first cloud function does not have infinite recursion.

[0010] In one embodiment, the method further includes: matching the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, then determining that the resources used by the first cloud function meet the abnormal resource consumption condition.

[0011] In one embodiment, the resource usage of the first cloud function is restricted, including: restricting the concurrency of the first cloud function.

[0012] In one embodiment, the concurrency of the first cloud function is limited, including: maintaining the current concurrency of the first cloud function unchanged; or reducing the concurrency of the first cloud function to a preset concurrency threshold.

[0013] Secondly, this application also provides an infinite recursion detection device for cloud functions. The device includes: a detection module, used to perform recursion detection on the code of the first cloud function before running the user-uploaded first cloud function, so as to determine whether the first cloud function has infinite recursion; and a monitoring module, used to allow the first cloud function to run if the recursion detection determines that the first cloud function does not have infinite recursion, and to monitor the resource usage of the first cloud function during the running of the first cloud function, and to restrict the resource usage of the first cloud function if the monitoring shows that the resources used by the first cloud function meet the abnormal resource consumption conditions.

[0014] In one embodiment, the detection module is specifically used to detect the call parameters of each function included in the first cloud function based on the code of the first cloud function, and obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, it detects whether other cloud functions called by the first cloud function call back the first cloud function, and obtains a second recursion detection result; and determines whether the first cloud function has infinite recursion based on the second recursion detection result.

[0015] In one embodiment, the calling parameters include the number of call stack layers. The detection module is specifically used to detect whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer threshold. If it exceeds the preset layer threshold, the first recursion detection result is determined to be that the first cloud function has infinite recursion. If it does not exceed the preset layer threshold, the first recursion detection result is determined to be that the first cloud function does not have infinite recursion.

[0016] In one embodiment, the detection module is specifically used to obtain the cloud function call chain of the first cloud function, wherein the first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function; and to determine whether each cloud function in the cloud function call chain calls back the first cloud function, so as to obtain the second recursive detection result.

[0017] In one embodiment, the detection module is specifically configured to output a prompt message to the user when the second recursion detection result indicates that other cloud functions called by the first cloud function have callbacks to the first cloud function, and determine whether the first cloud function has infinite recursion based on the indication information provided by the user based on the prompt message; if the second recursion detection result indicates that other cloud functions called by the first cloud function do not have callbacks to the first cloud function, then it is determined that the first cloud function does not have infinite recursion.

[0018] In one embodiment, the monitoring module includes a matching unit for matching the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition.

[0019] In one embodiment, the monitoring module is specifically used to limit the concurrency of the first cloud function.

[0020] In one embodiment, the monitoring module is specifically used to maintain the current concurrency of the first cloud function unchanged; or to reduce the concurrency of the first cloud function to a preset concurrency threshold.

[0021] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method described in any of the first aspects above.

[0022] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the method described in any of the first aspects above.

[0023] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the steps of the method described in any of the first aspects above.

[0024] The aforementioned method, apparatus, device, and storage medium for detecting infinite recursion in cloud functions perform recursion detection on the code of the first cloud function before running it, to determine whether infinite recursion exists in the first cloud function. If the recursion detection determines that the first cloud function does not have infinite recursion, then the first cloud function is allowed to run. During the execution of the first cloud function, the resource usage of the first cloud function is monitored. If the resource usage of the first cloud function meets the abnormal resource consumption condition, the resource usage of the first cloud function is restricted. In this way, by performing recursion detection on the code of the first cloud function before it runs and monitoring the resource usage of the first cloud function during its execution, infinite recursion in cloud functions is avoided through a dual approach. Attached Figure Description

[0025] Figure 1 This is a flowchart illustrating an infinite recursion detection method for cloud functions in one embodiment.

[0026] Figure 2 This is a schematic diagram of a process for recursively detecting the code of a first cloud function in one embodiment;

[0027] Figure 3 This is a schematic diagram of a process for monitoring the resource usage of a first cloud function in one embodiment;

[0028] Figure 4 This is a structural block diagram of an infinite recursive detection device for a cloud function in one embodiment;

[0029] Figure 5 This is a block diagram of an infinite recursive detection system for cloud functions in one embodiment;

[0030] Figure 6 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation

[0031] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0032] With the development of cloud computing technology, cloud functions, with their advantages of rapid deployment, elastic scaling, lightweight and low cost, and high resource utilization, have gradually become the main method of cloud computing applications. Cloud functions only require users to write code and define triggering events according to specifications; they don't need to worry about how the code runs or scales, and can be deployed and used directly in the cloud. Cloud functions are typically stateless and event-driven cloud services, with their specific runtime environment and elastic scaling maintained by the cloud service provider. Cloud functions are billed based on the resources used and are primarily used for real-time file and data processing.

[0033] Because cloud functions are extremely easy to expand and are billed based on usage, if a cloud function becomes infinitely recursive, its lightweight and infinitely scalable nature can easily lead to huge bills, placing an unexpected burden on users.

[0034] Currently, cloud service providers do not have specific restrictions on recursive calls to cloud functions. They only emphasize in the user manuals that users should avoid recursive calls in cloud functions. Some cloud service providers offer a button that can immediately reduce the concurrency of cloud functions to 0, but they do not automatically or proactively remind users that their cloud functions may have infinite recursion, nor are there automated mechanisms to limit the abuse of recursion in cloud functions. This makes it very easy for users to incur unexpectedly huge bills due to code problems.

[0035] Based on the above problems, it is necessary to propose effective technical means to solve them. The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0036] In one embodiment, such as Figure 1The diagram illustrates a method for detecting infinite recursion in cloud functions. The method is applied to a server for illustrative purposes and includes the following steps:

[0037] Step 101: Before running the first cloud function uploaded by the user, perform a recursion check on the code of the first cloud function to determine whether the first cloud function has infinite recursion.

[0038] Infinite recursion refers to a situation where a function recursively calls itself and cannot reach the recursion base.

[0039] Optionally, before running the user-uploaded first cloud function, the code of the first cloud function is pre-compiled to check the calling parameters of each function included in the first cloud function. If the calling parameters exceed a preset parameter threshold, it is determined that the first cloud function has infinite recursion; if the calling parameters do not exceed the preset parameter threshold, it is determined that the first cloud function does not have infinite recursion.

[0040] In another optional embodiment, before running the first cloud function uploaded by the user, it is detected whether other cloud functions called by the first cloud function call back the first cloud function. If there is a callback, it is determined that the first cloud function has infinite recursion; if there is no callback, it is determined that the first cloud function does not have infinite recursion.

[0041] In another optional embodiment, before running the first cloud function uploaded by the user, the code of the first cloud function is pre-compiled, the calling parameters of each function included in the first cloud function are detected, and if it is determined that the first cloud function does not have infinite recursion based on the calling parameters, it is then detected whether other cloud functions called by the first cloud function call back to the first cloud function, so as to determine whether the first cloud function has infinite recursion.

[0042] Step 102: If the recursion detection determines that the first cloud function does not have infinite recursion, then the first cloud function is allowed to run. During the running of the first cloud function, the resource usage of the first cloud function is monitored. If the resource usage of the first cloud function meets the abnormal resource consumption condition, the resource usage of the first cloud function is restricted.

[0043] The resources used by the first cloud function include at least one of the following parameters: CPU (Central Processing Unit) utilization, memory usage, disk usage, and network traffic. An abnormal resource consumption condition refers to the cloud function using resources exceeding a preset threshold.

[0044] There are two scenarios in which the first cloud function is determined not to have infinite recursion through recursion detection. One is that if the first cloud function is determined not to have infinite recursion in step 101, then the first cloud function is determined not to have infinite recursion. The second is that if the first cloud function is determined to have infinite recursion in step 101, then a prompt message is output to the user. When the user indicates that the first cloud function does not have infinite recursion based on the prompt message, then the first cloud function is determined not to have infinite recursion.

[0045] Optionally, if the recursion detection determines that the first cloud function does not have infinite recursion, the first cloud function is submitted to the cloud function resource management system, so that the cloud function resource management system can trigger the first cloud function according to the event and manage and provide the resources required by the first cloud function.

[0046] During the execution of the first cloud function, the resources consumed by the first cloud function are monitored in real time. If the resources consumed by the first cloud function exceed a preset limit threshold, or if the resources consumed by the first cloud function successfully match a rule in a preset rule base, then it is determined that the resources consumed by the first cloud function meet the abnormal resource consumption condition. Then, the API (Application Programming Interface) of the cloud function resource management system is called to restrict the resource usage of the first cloud function, such as limiting at least one of the following: the number of concurrent users and CPU utilization.

[0047] In the aforementioned method for detecting infinite recursion in cloud functions, a recursion check is performed on the code of the first cloud function before it is run to determine whether infinite recursion exists. If the recursion check determines that the first cloud function does not have infinite recursion, then the first cloud function is allowed to run. During the execution of the first cloud function, its resource usage is monitored. If the resource usage of the first cloud function meets the abnormal resource consumption condition, its resource usage is restricted. In this way, by performing a recursion check on the code of the first cloud function before it runs and monitoring its resource usage during its execution, infinite recursion in cloud functions is avoided through a dual approach.

[0048] In one embodiment, recursion detection is performed on the code of the first cloud function to determine whether the first cloud function has infinite recursion. This includes: based on the code of the first cloud function, detecting the call parameters of each function included in the first cloud function to obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, detecting whether other cloud functions called by the first cloud function call back to the first cloud function to obtain a second recursion detection result; and determining whether the first cloud function has infinite recursion based on the second recursion detection result.

[0049] Optional, such as Figure 2 The diagram illustrates a process for recursion detection of the code of a first cloud function. The call parameters include the call stack depth. The process involves detecting the call parameters of each function included in the first cloud function to obtain a first recursion detection result. This includes: checking whether the call stack depth of each function included in the first cloud function exceeds a preset threshold; if it exceeds the preset threshold, the first recursion detection result indicates that the first cloud function exhibits infinite recursion; if it does not exceed the preset threshold, the first recursion detection result indicates that the first cloud function does not exhibit infinite recursion. The preset threshold can be 1000 or 2000 layers, and can be set as needed; it is not limited here.

[0050] If the first recursion detection result indicates that the first cloud function has infinite recursion, output the first result information of recursion error to the user.

[0051] If the first recursive detection result indicates that the first cloud function does not have infinite recursion, then check whether other cloud functions called by the first cloud function call back to the first cloud function. If not, then determine that other cloud functions called by the first cloud function do not call back to the first cloud function if the second recursive detection result indicates that the first cloud function does. If so, then determine that other cloud functions called by the first cloud function do call back to the first cloud function if the second recursive detection result indicates that the first cloud function does.

[0052] If the second recursion check result indicates that no other cloud functions called by the first cloud function call back to the first cloud function, then it is determined that the first cloud function does not have infinite recursion. The first cloud function is then submitted to the cloud function resource management system, and a first result message indicating no recursion error is output to the user.

[0053] If the second recursion detection result indicates that other cloud functions called by the first cloud function have callbacks to the first cloud function, a prompt message is output to the user, and the user's feedback based on the prompt message is used to determine whether the first cloud function has infinite recursion.

[0054] If the instruction message indicates that the first cloud function does not have infinite recursion, then the first cloud function is submitted to the cloud function resource management system; if the instruction message indicates that the first cloud function has infinite recursion, then the execution of the next step, namely step 102, ends.

[0055] In this embodiment, based on the code of the first cloud function, the call parameters of each function included in the first cloud function are detected to obtain a first recursion detection result. If the first recursion detection result indicates that the first cloud function does not have infinite recursion, it is detected whether other cloud functions called by the first cloud function call back to the first cloud function to obtain a second recursion detection result. Based on the second recursion detection result, it is determined whether the first cloud function has infinite recursion. This achieves dual detection of the first cloud function before it runs. This method can greatly avoid infinite recursion of cloud functions, thereby reducing resource waste and huge bills caused by code errors in the first cloud function.

[0056] In one embodiment, detecting whether other cloud functions called by the first cloud function call back the first cloud function yields a second recursive detection result, including:

[0057] Step 201: Obtain the cloud function call chain of the first cloud function. The first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function.

[0058] Optionally, find the cloud function called by the first cloud function and name it a level 1 related cloud function; then find the cloud function called by the level 1 related cloud function and name it a level 2 related cloud function, and so on until no new related cloud functions are found, or until a preset level of related cloud function is found. This preset level of related cloud function can be a level 5 related cloud function. Arranging these different levels of related cloud functions in sequence will yield the cloud function call chain.

[0059] The first cloud function may call multiple cloud functions, therefore, the cloud function call chain of the first cloud function may also be multiple.

[0060] For example, the cloud functions called by the first cloud function are A1 and A2. A1 calls B1 and B2. A2 calls B3. B1 calls C1. B2 calls C2. B3 calls C3. C1 and C2 do not call any cloud functions. C3 calls D1. In this case, the cloud function call chain of the first cloud function is A1-B1-C1, A1-B2-C2, and A2-B3-C3-D1.

[0061] Step 202: Determine whether each cloud function in the cloud function call chain calls back the first cloud function to obtain the second recursive detection result.

[0062] Optionally, if it is detected that none of the cloud functions in the cloud function call chain have a callback to the first cloud function, then the second recursive detection result is that the other cloud functions called by the first cloud function do not have a callback to the first cloud function; if it is detected that at least one of the cloud functions in the cloud function call chain has a callback to the first cloud function, then the second recursive detection result is that the other cloud functions called by the first cloud function have a callback to the first cloud function.

[0063] Step 203: If the second recursion detection result indicates that other cloud functions called by the first cloud function have callbacks to the first cloud function, output a prompt message to the user, and determine whether the first cloud function has infinite recursion based on the user's feedback based on the prompt message.

[0064] The prompt information may include an identifier of the cloud function call chain that has a callback to the first cloud function, and the prompt information may also include the code segment of the cloud function that has a callback to the first cloud function.

[0065] In this embodiment, by obtaining the cloud function call chain of the first cloud function and then determining whether each cloud function in the cloud function call chain calls back to the first cloud function, a second recursion detection result is obtained. This realizes the detection of whether the first cloud function has infinite recursion, and then prompts the user if the first cloud function has infinite recursion, which can avoid infinite recursion of the cloud function.

[0066] In one embodiment, the method further includes: matching the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, then determining that the resources used by the first cloud function meet the abnormal resource consumption condition.

[0067] The preset rule base includes rules such as maximum resource limits for cloud functions, resource consumption limits per unit time, suspension time limits, and failure count limits. Maximum resource limits for cloud functions include at least one of the following: CPU utilization limits, memory usage limits, disk usage limits, and traffic limits. Additionally, users can define custom rules and modify parameters of the default rules.

[0068] The preset rule base also stores restriction instructions for the restriction cloud functions that correspond one-to-one with the rules.

[0069] Optional, such as Figure 3The diagram illustrates a process for monitoring the resource usage of a first cloud function. During the execution of the first cloud function, its resource usage is monitored to determine if it conforms to any rule in a preset rule base. If not, the monitoring continues; otherwise, resource usage is restricted according to the rule that the first cloud function conforms to. Specifically, resource usage can be restricted based on the restriction instruction corresponding to the rule. Then, a second result is output to the user. This second result includes at least one of a restriction processing log and a cloud function runtime exception message. The second result can be communicated to the user via at least one of email, SMS, WeChat, or telephone.

[0070] In this embodiment, the resource usage of the monitored first cloud function is matched with a preset rule base. If a match is found with a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition. In other words, the rules in the preset rule base are used to determine whether the resources used by the first cloud function meet the abnormal resource consumption condition. This achieves a quantitative judgment of the resource usage of the first cloud function and has the characteristics of being fast and highly accurate.

[0071] In one embodiment, the resource usage of the first cloud function is restricted, including: restricting the concurrency of the first cloud function.

[0072] Optionally, limiting the concurrency of the first cloud function includes: maintaining the current concurrency of the first cloud function unchanged; or reducing the concurrency of the first cloud function to a preset concurrency threshold.

[0073] The preset concurrency threshold can be 0, and it can be set as needed; no limit is imposed here.

[0074] Optionally, the concurrency of the first cloud function can be limited according to rules. If the resource consumption of the first cloud function exceeds a first consumption threshold, it indicates that the resource consumption of the first cloud function is severe. In this case, a first concurrency limit request is sent to the cloud function resource management system via API. The first concurrency limit request instructs the cloud function resource management system to reduce the concurrency of the first cloud function to a preset concurrency threshold. If the resource consumption of the first cloud function is greater than a second consumption threshold but less than the first consumption threshold, it indicates that the resource consumption of the first cloud function is not severe. In this case, a second concurrency limit request is sent to the cloud function resource management system via API. The second concurrency limit request instructs the cloud function resource management system to maintain the current concurrency of the first cloud function unchanged.

[0075] In this embodiment, only the API of the cloud function resource management system needs to be called without affecting the original service or requiring code modification. This greatly reduces the possibility of users accidentally triggering huge bills, allowing users to use cloud function services with greater peace of mind.

[0076] In summary, the detailed steps for implementing the infinite recursion detection method for cloud functions are as follows:

[0077] Step 301: Before running the first cloud function uploaded by the user, based on the code of the first cloud function, check whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer threshold. If it exceeds the preset layer threshold, the first recursion detection result is determined to be that the first cloud function has infinite recursion; if it does not exceed the preset layer threshold, the first recursion detection result is determined to be that the first cloud function does not have infinite recursion.

[0078] Step 302: If the first recursion detection result indicates that the first cloud function does not have infinite recursion, obtain the cloud function call chain of the first cloud function. The first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function. Determine whether each cloud function in the cloud function call chain calls back to the first cloud function to obtain the second recursion detection result.

[0079] Step 303: If the second recursion detection result indicates that other cloud functions called by the first cloud function have callbacks to the first cloud function, output a prompt message to the user and determine whether the first cloud function has infinite recursion based on the user's feedback based on the prompt message; if the second recursion detection result indicates that other cloud functions called by the first cloud function do not have callbacks to the first cloud function, then determine that the first cloud function does not have infinite recursion.

[0080] Step 304: If the recursion detection determines that the first cloud function does not have infinite recursion, then the first cloud function is allowed to run, and the resource usage of the first cloud function is monitored during the running of the first cloud function.

[0081] Step 305: Match the monitored resource usage of the first cloud function with a preset rule base; if it matches a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition.

[0082] Step 306: If it is detected that the resources used by the first cloud function meet the abnormal resource consumption conditions, maintain the current concurrency of the first cloud function unchanged; or, reduce the concurrency of the first cloud function to a preset concurrency threshold.

[0083] It should be understood that, although Figure 1-3The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 1-3 At least some of the steps in the process may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the steps or stages in other steps.

[0084] In one embodiment, such as Figure 4 As shown, an infinite recursion detection device for cloud functions is provided. The infinite recursion detection device 400 for cloud functions includes: a detection module 401 and a monitoring module 402, wherein:

[0085] The detection module 401 is used to perform recursive detection on the code of the first cloud function before running the first cloud function uploaded by the user, so as to determine whether the first cloud function has infinite recursion.

[0086] The monitoring module 402 is used to allow the first cloud function to run if it is determined through recursion detection that the first cloud function does not have infinite recursion, and to monitor the resource usage of the first cloud function during the running of the first cloud function. If the monitoring detects that the resources used by the first cloud function meet the abnormal resource consumption conditions, the monitoring module 402 will restrict the resource usage of the first cloud function.

[0087] In one embodiment, the detection module 401 is specifically used to detect the call parameters of each function included in the first cloud function based on the code of the first cloud function, and obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, it detects whether other cloud functions called by the first cloud function call back the first cloud function, and obtains a second recursion detection result; and determines whether the first cloud function has infinite recursion based on the second recursion detection result.

[0088] In one embodiment, the calling parameters include the number of call stack layers. The detection module 401 is specifically used to detect whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer threshold. If it exceeds the preset layer threshold, the first recursion detection result is determined to be that the first cloud function has infinite recursion. If it does not exceed the preset layer threshold, the first recursion detection result is determined to be that the first cloud function does not have infinite recursion.

[0089] In one embodiment, the detection module 401 is specifically used to obtain the cloud function call chain of the first cloud function, wherein the first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function; and to determine whether each cloud function in the cloud function call chain calls back the first cloud function, so as to obtain the second recursive detection result.

[0090] In one embodiment, the detection module 401 is specifically used to output a prompt message to the user when the second recursion detection result is that other cloud functions called by the first cloud function have a callback to the first cloud function, and to determine whether the first cloud function has infinite recursion based on the indication information fed back by the user based on the prompt message; if the second recursion detection result is that other cloud functions called by the first cloud function do not have a callback to the first cloud function, then it is determined that the first cloud function does not have infinite recursion.

[0091] In one embodiment, the monitoring module 402 includes a matching unit for matching the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition.

[0092] In one embodiment, the monitoring module 402 is specifically used to limit the number of concurrent connections to the first cloud function.

[0093] In one embodiment, the monitoring module 402 is specifically used to maintain the current concurrency of the first cloud function unchanged; or to reduce the concurrency of the first cloud function to a preset concurrency threshold.

[0094] Specific limitations regarding the infinite recursion detection device for cloud functions can be found in the limitations of the infinite recursion detection method for cloud functions described above, and will not be repeated here. Each module in the aforementioned infinite recursion detection device for cloud functions can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.

[0095] In one embodiment, such as Figure 5 As shown, an infinite recursion detection system for cloud functions is provided. The infinite recursion detection system for cloud functions includes: a terminal for users to upload the first cloud function, a cloud function resource management system and an infinite recursion detection device for cloud functions, and a server that deploys cloud function services.

[0096] The infinite recursion detection device for cloud functions includes a detection module and a monitoring module. The detection module includes a code detection unit, a cloud function analysis unit, and a cloud function submission unit; the monitoring module includes a resource monitoring unit, a matching unit, a restriction processing unit, and a notification unit.

[0097] The steps executed by the infinite recursion detection system for cloud functions are as follows:

[0098] Step 501: The code detection unit receives the code of the first cloud function uploaded by the user and checks whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer threshold. If it exceeds the preset layer threshold, the first recursion detection result is determined to be that the first cloud function has infinite recursion. If it does not exceed the preset layer threshold, the first recursion detection result is determined to be that the first cloud function does not have infinite recursion.

[0099] If the first recursion detection result indicates that the first cloud function does not have infinite recursion, the cloud function analysis unit obtains the cloud function call chain of the first cloud function and determines whether each cloud function in the cloud function call chain calls back to the first cloud function in order to obtain the second recursion detection result.

[0100] Step 502: If the cloud function submission unit determines that the first cloud function does not have infinite recursion when none of the cloud functions in the cloud function call chain of the first cloud function have called back the first cloud function (i.e., the detection has passed), then it submits the code of the first cloud function to the cloud function resource management system.

[0101] Step 503: The cloud function resource management system triggers the first cloud function based on the event.

[0102] Step 504: The cloud function service controls the execution of the first cloud function, implementing recursive calls to the first cloud function.

[0103] Step 505: During the operation of the first cloud function, the resource monitoring unit monitors the resource usage of the first cloud function.

[0104] The matching unit will match the resource usage of the first cloud function it monitors with the preset rule base.

[0105] If the resource usage of the first cloud function is successfully matched with a rule in the preset rule base, the restriction processing unit will restrict the resource usage of the first cloud function.

[0106] The notification unit outputs information about abnormal detection results to the terminal.

[0107] Specific limitations regarding the infinite recursion detection system for cloud functions can be found in the limitations of the infinite recursion detection method for cloud functions described above, and will not be repeated here. Each module in the aforementioned infinite recursion detection system for cloud functions can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the memory of a computer device in software form, so that the processor can call and execute the corresponding operations of each module.

[0108] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6 As shown, this computer device includes a processor, memory, input / output (I / O) interfaces, and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores multiple second text vectors and different log types corresponding to these second text vectors. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a compilation method.

[0109] Those skilled in the art will understand that Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.

[0110] In one embodiment, a computer device is provided. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps in any of the method embodiments described above.

[0111] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in any of the above method embodiments.

[0112] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in any of the above method embodiments.

[0113] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.

[0114] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0115] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.

Claims

1. A method for detecting infinite recursion of cloud functions, characterized in that, The method includes: Before running the first cloud function uploaded by the user, the code of the first cloud function is recursively checked to determine whether the first cloud function has infinite recursion. If the recursion detection determines that the first cloud function does not have infinite recursion, then the first cloud function is allowed to run. During the running of the first cloud function, the resource usage of the first cloud function is monitored. If the resource usage of the first cloud function meets the abnormal resource consumption condition, the resource usage of the first cloud function is restricted. The step of performing recursion detection on the code of the first cloud function to determine whether the first cloud function has infinite recursion includes: based on the code of the first cloud function, detecting the call parameters of each function included in the first cloud function to obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, detecting whether other cloud functions called by the first cloud function call back the first cloud function to obtain a second recursion detection result; and determining whether the first cloud function has infinite recursion based on the second recursion detection result. The step of detecting the call parameters of each function included in the first cloud function based on the code of the first cloud function to obtain a first recursion detection result includes: detecting whether the call stack level of each function included in the first cloud function exceeds a preset level threshold; if it exceeds the preset level threshold, then determining that the first recursion detection result indicates that the first cloud function has infinite recursion; if it does not exceed the preset level threshold, then determining that the first recursion detection result indicates that the first cloud function does not have infinite recursion. Determining whether the first cloud function has infinite recursion based on the second recursion detection result includes: if the second recursion detection result indicates that other cloud functions called by the first cloud function have callbacks to the first cloud function, outputting a prompt message to the user, and determining whether the first cloud function has infinite recursion based on the indication information fed back by the user based on the prompt message; The method further includes: matching the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition.

2. The method according to claim 1, characterized in that, The rules in the preset rule base include: maximum resource limit, resource consumption limit per unit time, suspension time limit, and failure count limit.

3. The method according to claim 2, characterized in that, The step of detecting whether other cloud functions called by the first cloud function call back the first cloud function to obtain a second recursive detection result includes: Obtain the cloud function call chain of the first cloud function, wherein the first cloud function in the cloud function call chain is called by the first cloud function, and the non-first cloud function in the cloud function call chain is called by the preceding cloud function; Determine whether each cloud function in the cloud function call chain calls back the first cloud function to obtain the second recursive detection result.

4. The method according to claim 3, characterized in that, Determining whether the first cloud function has infinite recursion based on the second recursion detection result includes: If the second recursion detection result indicates that no other cloud function called by the first cloud function calls back the first cloud function, then it is determined that the first cloud function does not have infinite recursion.

5. The method according to any one of claims 1 to 4, characterized in that, The restriction on resource usage of the first cloud function includes: The concurrency of the first cloud function is limited.

6. The method according to claim 5, characterized in that, The process of limiting the concurrency of the first cloud function includes: Maintain the current concurrency level of the first cloud function; or, The concurrency of the first cloud function is reduced to a preset concurrency threshold.

7. An infinite recursion detection device for cloud functions, characterized in that, The device includes: The detection module is used to perform recursive detection on the code of the first cloud function before running the first cloud function uploaded by the user, in order to determine whether the first cloud function has infinite recursion; The monitoring module is used to allow the first cloud function to run if it is determined through the recursion detection that the first cloud function does not have infinite recursion, and to monitor the resource usage of the first cloud function during the running of the first cloud function. If the monitoring detects that the resources used by the first cloud function meet the abnormal resource consumption conditions, the monitoring module will restrict the resource usage of the first cloud function. The detection module is specifically used to detect the call parameters of each function included in the first cloud function based on the code of the first cloud function, and obtain a first recursion detection result; if the first recursion detection result indicates that the first cloud function does not have infinite recursion, it detects whether other cloud functions called by the first cloud function call back the first cloud function, and obtains a second recursion detection result; and determines whether the first cloud function has infinite recursion based on the second recursion detection result. The detection module is specifically used to detect whether the number of call stack layers of each function included in the first cloud function exceeds a preset layer threshold; if it exceeds the preset layer threshold, the first recursion detection result is determined to be that the first cloud function has infinite recursion; if it does not exceed the preset layer threshold, the first recursion detection result is determined to be that the first cloud function does not have infinite recursion. The detection module is specifically used to output a prompt message to the user when the second recursive detection result is that other cloud functions called by the first cloud function have a callback to the first cloud function, and to determine whether the first cloud function has infinite recursion based on the indication information fed back by the user based on the prompt message. The matching module is used to match the monitored resource usage of the first cloud function with a preset rule base; if a match is found with a rule in the preset rule base, it is determined that the resources used by the first cloud function meet the abnormal resource consumption condition.

8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • PREDICTING EXECUTION DURATION FOR USER-DEFINED FUNCTIONS ON FUNCTION-AS-A-SERVICE (FaaS) CLOUD COMPUTING PLATFORMS

    US20210334107A1