简体   繁体   English

WCF调用时出现内存不足异常

[英]Out of memory Exception at WCF call

Our server is running in production environment, but after running for few days, out of memory exception occurs at WCF call. 我们的服务器正在生产环境中运行,但是运行几天后,在WCF调用中发生内存不足异常。

Line 36007:    GlobalUnhandledException: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
Line 36063:    at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
Line 36063:    at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
Line 36064:    at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
Line 36065:    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

We have try to give the maximum array size in configuration. 我们尝试在配置中提供最大的阵列大小。 Binding configuration of WCF at server side. 服务器端WCF的绑定配置。

<netTcpBinding>
    <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288" sendTimeout="00:00:35" transactionFlow="true"  >
      <reliableSession enabled="true" />
      <security mode="None" />
    </binding>
  </netTcpBinding>

Is there is memory leak issue happening at WCF connection calls? WCF连接调用中是否发生内存泄漏问题?

Service behaviour: 服务行为:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall,
                 ConcurrencyMode = ConcurrencyMode.Multiple,
                 ReleaseServiceInstanceOnTransactionComplete = false)]

Is there something I missed during configuration, what are steps to rectify or identify this out of memory exception any help on this matter is appreciated. 我在配置过程中有什么遗漏的地方吗?有什么步骤可以纠正或识别出内存不足的异常,请多多关照。

UPDATE: Operation contract: 更新:操作合同:

[OperationContract]
    [TransactionFlow(TransactionFlowOption.Allowed)]

Yes, your configuration is the issue. 是的,您的配置是问题所在。

This is what your configuration means: 这是您的配置的意思:

InstanceContextMode = InstanceContextMode.PerCall - Start a new service instance for each call made to the service. InstanceContextMode = InstanceContextMode.PerCall为对服务的每次调用启动一个新的服务实例。

ConcurrencyMode = ConcurrencyMode.Multiple - Allow multiple threads to start within the service instance ConcurrencyMode = ConcurrencyMode.Multiple允许多个线程在服务实例中启动

ReleaseServiceInstanceOnTransactionComplete = false - Do not release the service instance once the call is complete. ReleaseServiceInstanceOnTransactionComplete = false调用完成后请勿释放服务实例。

EDIT: 编辑:

Based on your OperationContract for the method, I would specify the OperationBehaviour for the method and configure the Transaction completion behaviour according to your needs. 根据您的OperationContract的方法,我会指定OperationBehaviour的方法,并根据自己的需要配置完成的交易行为。

MSDN for ReleaseInstanceOnTransaction - has a good example of how OperationBehaviour should be configured to automatically complete the Transaction once the underlying operation has completed. MSDN for ReleaseInstanceOnTransaction-有一个很好的示例,说明应如何配置OperationBehaviour以在基础操作完成后自动完成事务。

The underlying cause of your OutOfMemoryException is highly likely to be not completing Transactions and thus not causing the WCF ServiceInstance to be shutdown and garbage collected. OutOfMemoryException的根本原因很可能是未完成事务,因此也没有导致WCF ServiceInstance被关闭和垃圾回收。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM