IronPDF Azure コンテナでの gRPC 接続エラー
IronPDF が Azure Container Instances や Azure App Service 上の Docker コンテナ内にデプロイされると、アプリケーションと IronPDF エンジン間の gRPC 通信が失敗することがあります。 この問題は、主にコンテナがアイドル状態になったり再起動したりした後や、gRPC チャンネルがリトライロジックで構成されていない場合に発生します。
Grpc.Core.RpcException: Status(StatusCode="Unavailable", Detail="failed to connect to all addresses")
Status(StatusCode="Unknown", Detail="Stream removed")
これらのエラーは、Azure のコンテナ環境がアイドル期間中にコンテナをシャットダウンまたはリサイクルする場合に発生します。 gRPC チャンネルにリトライポリシーがないと、単一の接続が切断された場合に、即座にコールが失敗し、再接続されません。 HTTP/2 ストリームの閉鎖およびプラットフォーム特有のチャンネルセットアップの不一致も、これらのエラーを引き起こす可能性があります。
解決策
1. コンテナの再起動ポリシーを Always に設定する
Azure Container Instances では、再起動ポリシーを Always に設定してください。 Azure App Service では、コンテナをスケールダウンして終了させる消費プランではなく、専用プラン (Basic B1 以上) を使用してください。 永続的な接続が必要なワークロードには、Kubernetes 管理のコンテナがより安定したオプションです。
2. gRPC リトライロジックを構成する
目指すフレームワークに合ったアプローチを選択してください。
.NET Framework 用: JSON リトライポリシーを使用した Grpc.Core.Channel を使用
using Grpc.Core;
using IronPdf.GrpcLayer;
string jsonString = @"
{
""methodConfig"": [
{
""name"": [
{
""service"": ""ironpdfengineproto.IronPdfService""
}
],
""retryPolicy"": {
""maxAttempts"": 5,
""initialBackoff"": ""1.0s"",
""maxBackoff"": ""30s"",
""backoffMultiplier"": 1.5,
""retryableStatusCodes"": [
""UNAVAILABLE""
]
}
}
]
}";
var channel = new Channel("localhost:33350", ChannelCredentials.Insecure,
new[]
{
new ChannelOption("grpc.service_config", jsonString)
});
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
);
using Grpc.Core;
using IronPdf.GrpcLayer;
string jsonString = @"
{
""methodConfig"": [
{
""name"": [
{
""service"": ""ironpdfengineproto.IronPdfService""
}
],
""retryPolicy"": {
""maxAttempts"": 5,
""initialBackoff"": ""1.0s"",
""maxBackoff"": ""30s"",
""backoffMultiplier"": 1.5,
""retryableStatusCodes"": [
""UNAVAILABLE""
]
}
}
]
}";
var channel = new Channel("localhost:33350", ChannelCredentials.Insecure,
new[]
{
new ChannelOption("grpc.service_config", jsonString)
});
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
);
Imports Grpc.Core
Imports IronPdf.GrpcLayer
Dim jsonString As String = "
{
""methodConfig"": [
{
""name"": [
{
""service"": ""ironpdfengineproto.IronPdfService""
}
],
""retryPolicy"": {
""maxAttempts"": 5,
""initialBackoff"": ""1.0s"",
""maxBackoff"": ""30s"",
""backoffMultiplier"": 1.5,
""retryableStatusCodes"": [
""UNAVAILABLE""
]
}
}
]
}"
Dim channel = New Channel("localhost:33350", ChannelCredentials.Insecure,
{
New ChannelOption("grpc.service_config", jsonString)
})
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
)
.NET Core / .NET 5+ 用: Grpc.Net.Client.GrpcChannel と RetryPolicy を使用
using Grpc.Net.Client;
using Grpc.Net.Client.Configuration;
using IronPdf.GrpcLayer;
using Grpc.Core;
var retryPolicy = new RetryPolicy
{
MaxAttempts = 5,
InitialBackoff = TimeSpan.FromSeconds(1),
MaxBackoff = TimeSpan.FromSeconds(30),
BackoffMultiplier = 1.5,
RetryableStatusCodes = { StatusCode.Unavailable }
};
var methodConfig = new MethodConfig
{
Names = { MethodName.Default },
RetryPolicy = retryPolicy
};
var channel = GrpcChannel.ForAddress("http://localhost:33350", new GrpcChannelOptions
{
ServiceConfig = new ServiceConfig { MethodConfigs = { methodConfig } }
});
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
);
using Grpc.Net.Client;
using Grpc.Net.Client.Configuration;
using IronPdf.GrpcLayer;
using Grpc.Core;
var retryPolicy = new RetryPolicy
{
MaxAttempts = 5,
InitialBackoff = TimeSpan.FromSeconds(1),
MaxBackoff = TimeSpan.FromSeconds(30),
BackoffMultiplier = 1.5,
RetryableStatusCodes = { StatusCode.Unavailable }
};
var methodConfig = new MethodConfig
{
Names = { MethodName.Default },
RetryPolicy = retryPolicy
};
var channel = GrpcChannel.ForAddress("http://localhost:33350", new GrpcChannelOptions
{
ServiceConfig = new ServiceConfig { MethodConfigs = { methodConfig } }
});
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
);
Imports Grpc.Net.Client
Imports Grpc.Net.Client.Configuration
Imports IronPdf.GrpcLayer
Imports Grpc.Core
Dim retryPolicy As New RetryPolicy With {
.MaxAttempts = 5,
.InitialBackoff = TimeSpan.FromSeconds(1),
.MaxBackoff = TimeSpan.FromSeconds(30),
.BackoffMultiplier = 1.5,
.RetryableStatusCodes = {StatusCode.Unavailable}
}
Dim methodConfig As New MethodConfig With {
.Names = {MethodName.Default},
.RetryPolicy = retryPolicy
}
Dim channel As GrpcChannel = GrpcChannel.ForAddress("http://localhost:33350", New GrpcChannelOptions With {
.ServiceConfig = New ServiceConfig With {.MethodConfigs = {methodConfig}}
})
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.WithCustomChannel(channel)
)
3. より単純な設定には RemoteServer を使用する
カスタムチャネルオプションが不要な場合、RemoteServer は組み込みのリトライサポートを提供し、ほとんどの Azure コンテナ配備の推奨開始点です。 エンジンとアプリケーションコンテナが同じローカルネットワークにない場合は、.Docker() の代わりにこれを使用してください。 完全な接続設定のリファレンスについては、IronPDF Engine ガイドをご覧ください。
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.RemoteServer("http://your-container-host:33350")
);
IronPdf.Installation.ConnectToIronPdfHost(
IronPdfConnectionConfiguration.RemoteServer("http://your-container-host:33350")
);
Imports IronPdf
IronPdf.Installation.ConnectToIronPdfHost( _
IronPdfConnectionConfiguration.RemoteServer("http://your-container-host:33350") _
)
4. リクエスト間でのエンジンシャットダウンを防ぐ
デフォルトでは、IronPDF はリクエスト間でエンジンをシャットダウンします。 SkipShutdown を true に設定すると、エンジンプロセスが維持され、再接続の負荷を回避し、長時間稼働するコンテナでの接続エラーの可能性を減少させます。
IronPdf.Installation.SkipShutdown = true;
IronPdf.Installation.SkipShutdown = true;
IronPdf.Installation.SkipShutdown = True
デバッグのヒント
詳細な gRPC 診断出力を得るには、以下の環境変数を Dockerfile またはコンテナ構成に設定してください:
ENV GRPC_TRACE=all
ENV GRPC_VERBOSITY=DEBUG
接続失敗に関する追加の詳細については、cef.log と IronSoftware.log を確認してください。 Azure からログファイルを取得する方法については、Azure ログファイルを参照してください。

