快速版本:为什么我的函数宿主在5分钟后不执行任何操作会自行杀死它?
我有一个Azure函数,该函数使用nClam扫描blob文件中的病毒。它似乎工作正常,但突然之间,即使在触发任何斑点之前,它也会自行杀死!它将在5分钟后关闭,并显示OutOfMemoryException:
[18/9/2019 10:33:33] Host initialized (405ms)
[18/9/2019 10:33:33] Host started (812ms)
[18/9/2019 10:33:33] Job host started
Hosting environment: Production
Content root path: D:\git\TopoAPI\Antivirus\bin\Debug\netcoreapp2.1
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.
[18/9/2019 10:33:38] Host lock lease acquired by instance ID '000000000000000000000000C913FBA0'.
[18/9/2019 10:38:46] An unhandled exception has occurred. Host is shutting down.
[18/9/2019 10:38:46] Microsoft.WindowsAzure.Storage: Exception of type 'System.OutOfMemoryException' was thrown. System.Private.CoreLib: Exception of type 'System.OutOfMemoryException' was thrown.
[18/9/2019 10:38:46] Stopping host...
[18/9/2019 10:38:46] Stopping JobHost
[18/9/2019 10:38:46] Job host stopped
[18/9/2019 10:38:46] Host shutdown completed.
Application is shutting down...
下面是我的扫描Blob触发函数:
[FunctionName("scanImports")]
public static async Task Scan([BlobTrigger("imports/{newBlobName}", Connection = "BlobConnectionstring")]CloudBlockBlob newBlob, string newBlobName, ILogger log, ExecutionContext context)
{
var config = new ConfigurationBuilder().SetBasePath(context.FunctionAppDirectory).AddJsonFile("local.settings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();
var clamClient = new ClamClient(config["ContainerAddress"], int.Parse(config["ContainerPort"]));
var blobFileStream = await newBlob.OpenReadAsync();
using (var memoryStream = new MemoryStream())
{
await blobFileStream.CopyToAsync(memoryStream);
var result = await clamClient.SendAndScanFileAsync(memoryStream.ToArray());
bool isClean = result.InfectedFiles == null || result.InfectedFiles.Count == 0;
// Check if newBlob is infected. If infected, move to quarantineBlob
if (!isClean)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(config["blobConnectionstring"]);
CloudBlobClient client;
CloudBlobContainer container;
CloudBlockBlob quarantineBlob;
client = storageAccount.CreateCloudBlobClient();
container = client.GetContainerReference(config["QuarantineBlobName"]);
await container.CreateIfNotExistsAsync();
quarantineBlob = container.GetBlockBlobReference(newBlobName);
quarantineBlob.Properties.ContentType = newBlob.Properties.ContentType;
await quarantineBlob.UploadFromStreamAsync(memoryStream);
await newBlob.DeleteAsync();
}
}
}
更新1::主机恰好在5分钟后死于OutOfMemoryException。我试图延长功能超时,这没有什么区别。 在此期间,该进程将持续使用5-8%的CPU,而在死之前,该进程将使用1500 MB以上的内存。
更新2:如果我从该函数中删除了所有代码,仅保留了一个log.info()语句,则主机在5分钟后仍会使用OutOfMemoryException自行杀死它
答案 0 :(得分:1)
Azure功能默认情况下具有5分钟的使用寿命。之后,它会自杀。
如果您将azure函数托管在App Service Plan上,则可以在host.json中将<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="ui basic small button instructor-button" data-toggles="Instructor A">
Instructor A
</button>
<button class="ui basic small button instructor-button" data-toggles="Instructor B">
Instructor B
</button>
<div class="reviews">
<div class="review" data-instructor="Instructor A">
// elements for review A
</div>
<div class="review" data-instructor="Instructor B">
// elements for review B
</div>
</div>
值设置为更高的值
指示所有功能的超时时间。
在无服务器消费计划中,有效范围是1秒到10分钟,默认值是5分钟。
在App Service计划中,没有总体限制,默认值取决于运行时版本。
在2.x版中,App Service计划的默认值为30分钟。
在1.x版中,它为null,表示没有超时。不能将其设置为infinite。 如果我们未明确设置此值,则将采用默认的30分钟值。
https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout
答案 1 :(得分:1)
我的问题的原因是我试图触发的Blob中包含100.000+个文件。 Microsoft将其定义为High scale。
所以我的代码实际上没有问题。只是如果我尝试在“高级” blob上触发,那么我的代码只会分配内存并死掉,什么也不会做。