google-cloud-platformgoogle-cloud-functions

Will a Cloud Function finish if HTTP request is cancelled?


I have a Python 3.7 Cloud Function that is triggered via HTTP request.

Function execution can take up to several seconds (2-5).

In some cases, the HTTP request is sent using Javascript from the website's front end.

My questions is, will the Cloud Function finish it's execution normally even if the browser window (that triggered the HTTP request using JS) is closed or user navigates to another page. The function returns "ok" but in that case it doesn't have a destination where to return it.


Solution

  • The function code doesn't do anything differently based on what happens to the client after the request is sent. In fact, it is not even possible to try to cancel the function's execution after the request has been sent.

    Closing the connection doesn't affect the outcome from the function's point of view. If a client closes the connection before the response is received, it will just not receive any response generated by the function, so you can not be certain if the client acted on any information returned by the function.