以前の案件で、リモーティングを使った環境で5分放置すると、リモーティングサーバーとの接続が切れてしまうという問題が出ていた。これ、Lease Timeという設定が5分になっていることに起因する。
以前は設定ファイルを読み込むタイプで運用していたので、以下のように設定ファイルの「lifetime/leaseTime」という設定をゼロにすることで、リースタイムを無期限にするという対応を取っていた(設定ファイル中のアスタリスクは伏せ字)。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<lifetime
leaseTime="0"
sponsorshipTimeOut="0"
renewOnCallTime="0"
/>
<service>
<wellknown
mode="Singleton"
type="***.Remoting.StringArray, ***Remoting"
objectUri="StringArray.rem"
/>
</service>
<channels>
<channel ref="http" port="8989"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>今回の案件も一部でRemotingを利用しているが、XMLでの設定ファイルが今回の案件では公式に認められなかったために、コード中に実装したところ、リースタイムの設定をすっかりすっぽかしてしまって問題が再発してしまった。
この設定値をコードで書く場合、MSDNの「System.Runtime.Remoting.LifeTime階層」にある説明だと、以下のようなコードをリモーティングサーバー側に記述することで同等の設定が可能なようだ。
Imports System
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Http
Imports System.Runtime.Remoting.Lifetime
Public Class Server
Public Shared Sub Main()
LifetimeServices.LeaseTime = TimeSpan.FromSeconds(5)実際うまくいったとの報告が先ほどあったばかり。
