From 6540241e746d0aee693bf1310184bab9d588e339 Mon Sep 17 00:00:00 2001 From: Fabio Cavalcante Date: Sun, 17 Nov 2024 10:40:58 -0800 Subject: [PATCH] Ensuring JobHost restart suppresion aligns with request lifecycle --- release_notes.md | 1 + .../Controllers/FunctionsController.cs | 21 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/release_notes.md b/release_notes.md index 04cc5ac22b..ebb21ad57a 100644 --- a/release_notes.md +++ b/release_notes.md @@ -6,3 +6,4 @@ - Introduced proper handling in environments where .NET in-proc is not supported. - Updated System.Memory.Data reference to 8.0.1 - Address issue with HTTP proxying throwing `ArgumentException` (#10616) +- Updated JobHost restart suppresion in functions APIs to align with request lifecycle (#10638) diff --git a/src/WebJobs.Script.WebHost/Controllers/FunctionsController.cs b/src/WebJobs.Script.WebHost/Controllers/FunctionsController.cs index 377f7761eb..5a4186c35e 100644 --- a/src/WebJobs.Script.WebHost/Controllers/FunctionsController.cs +++ b/src/WebJobs.Script.WebHost/Controllers/FunctionsController.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs.Extensions.Http; +using Microsoft.Azure.WebJobs.Host; using Microsoft.Azure.WebJobs.Script.Description; using Microsoft.Azure.WebJobs.Script.Management.Models; using Microsoft.Azure.WebJobs.Script.WebHost.Extensions; @@ -80,12 +81,10 @@ public async Task CreateOrUpdate(string name, [FromBody] Function return BadRequest($"{name} is not a valid function name"); } - bool success, configChanged; - FunctionMetadataResponse functionMetadataResponse; - using (fileMonitoringService.SuspendRestart(true)) - { - (success, configChanged, functionMetadataResponse) = await _functionsManager.CreateOrUpdate(name, functionMetadata, Request); - } + var restartSuspensionScope = fileMonitoringService.SuspendRestart(true); + Response.RegisterForDispose(restartSuspensionScope); + + (bool success, _, FunctionMetadataResponse functionMetadataResponse) = await _functionsManager.CreateOrUpdate(name, functionMetadata, Request); if (success) { @@ -200,12 +199,10 @@ public async Task Delete(string name, [FromServices] IFileMonitor return NotFound(); } - bool deleted; - string error; - using (fileMonitoringService.SuspendRestart(true)) - { - (deleted, error) = await _functionsManager.TryDeleteFunction(function); - } + var restartSuspensionScope = fileMonitoringService.SuspendRestart(true); + Response.RegisterForDispose(restartSuspensionScope); + + (bool deleted, string error) = await _functionsManager.TryDeleteFunction(function); if (deleted) {