測試台ASP.NET 4.0網站在程式更新後,每隔一兩分鐘便出現Session遺失狀況。進行檢查,發現事件檢視器在每次Session遺失的當下,會連續出現三個錯誤事件:

** Event ID 1325 Source: ASP.NET 4.0.30319.0 **

Exception: System.Runtime.Serialization.SerializationException

Message: Type 'System.ServiceModel.Dispatcher.NetDispatcherFaultException' in Assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

StackTrace:    at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
   at System.Runtime.Remoting.Channels.CrossAppDomainSerializer.SerializeObject(Object obj, MemoryStream stm)
   at System.AppDomain.Serialize(Object o)
   at System.AppDomain.MarshalObject(Object o)

** Event ID 1026 Source: .NET Runtime **

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.TargetInvocationException
Stack:
   at System.RuntimeMethodHandle._InvokeMethodFast(System.IRuntimeMethodInfo, System.Object, System.Object[], System.SignatureStruct ByRef, System.Reflection.MethodAttributes, System.RuntimeType)
   at System.RuntimeMethodHandle.InvokeMethodFast(System.IRuntimeMethodInfo, System.Object, System.Object[], System.Signature, System.Reflection.MethodAttributes, System.RuntimeType)
   at System.Reflection.RuntimeMethodInfo.Invoke(System.Object, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, Boolean)
   at System.Delegate.DynamicInvokeImpl(System.Object[])
   at Yuanta.Utility.Cache.CacheManagerInfo.SetCache()
   at System.Threading.ExecutionContext.runTryCode(System.Object)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

** Event ID 1000 Source: Application Error **

Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17651, time stamp: 0x4e21213c
Exception code: 0xe0434352
Fault offset: 0x000000000000cacd
Faulting process id: 0x1330
Faulting application start time: 0x01ccfcc575dce2b0
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\system32\KERNELBASE.dll
Report Id: 58b53cc8-68b9-11e1-a5d0-005056ac0022

依訊息內容,可解讀為ASP.NET Process在試圖序列化NetDispatcherFaultException時,因該Exception物件未標註為Serializable出錯,但因未適當處理Exception導致整個w3wp.exe Process掛掉,而保存其中的Session資料也跟著消失;後續網頁存取時,IIS會重新建立w3wp.exe,功能依舊,但已無原先保存的Session內容,如此足以解釋Session遺失現象。

看到System.Runtime.Remoting.Channels.CrossAppDomainSerializer字眼,聯想到可能與ASP.NET網站在一啟動後就會呼叫另一台WCF服務取得資料有關(呼叫WCF算是Remoting、也一定會用到序列化),而追查發現問題發生在今天更新ASP.NET程式後,而WCF並未更新換版,試著重新編譯部署新版WCF後,問題消失。

因測試期限壓力,沒再繼續挖掘這椿"WCF謀殺ASP.NET案件"的具體手法,只簡單歸納結論:

"ASP.NET 4.0在呼叫WCF的底層程式中似乎存在Bug,在遇到特定WCF錯誤時,會因NetDispatcherFaultException無法序列化而導致w3wp.exe整個Crash"

先筆記下來,未來遇到類似情境再併案調查。


Comments

# by Phoenix

"因該Exception物件未標註為Serializable出錯",是錯字嗎?應該、因該@@

# by Jeffrey

to Phoenix, 原意是"因為該Exception物件未...",簡寫為"因該Exception物件未...",呵! 看起來中英文交雜再加簡寫會讓文意不易理解,未來會注意。謝謝回饋~

# by 貓咪圓滾滾

那請黑大下次全部都用英文寫 那應該就不會有看不懂的困擾了 哈哈

# by 貓咪圓滾滾

我打得字有出現了耶 好感動啊 請問黑大 甚麼是URL? 是說如果留言的人有自己的部落格 那可以把連結放在那個選項內?

# by 貓咪圓滾滾

其實是這樣 我本來是想我問得問題恐怕太過高深 所以當然需要給黑大時間思考一下 不過今天下午研讀黑大的部落格後 我開始很擔心不曉得幾天後黑大下一篇新文章的標題會不會出現"網友發問注意事項! 請記得配合部落格格主魔人的身分!" 哈哈 然後更擔心 萬一黑大很認真解釋後 才悲慘發現這位網友根本沒有任何URL可以選擇性的放上去 哈哈 黑大放心 下次我會記得只要發問慢跑 小朋友創作跟水電工的事 要不然也得事前勤加模擬發問問題的深度 謝謝黑大! 哈哈

# by 貓咪圓滾滾

請黑大參考 Generation code http://www.bbc.co.uk/news/technology-17373972 文章內 英國的Year8大概是台灣的國二 不過他們的學制是從國中開始就有選修跟必修課程

# by Jeffrey

to 貓咪圓滾滾, 你指的是留言欄姓名下方的URL欄位嗎? 如果想提供大家進一步了解你的資訊,可在其中填入你個人Blog、Facebook、twitter或Plurk的URL,則在留言清單中,你的姓名上就會出現該連結囉~

# by 貓咪圓滾滾

很感謝黑大的詳細解釋 之前會把帳號關掉 我想當然不是貓咪的錯 而是我自己的思考方向很有問題 長時間以來 我從來都不是網路人 所以對網路的生態環境也很天真 不過不管怎樣 即便經歷過一些事 我還是只想做自己 也只能做自己 那在看了好幾天黑大的部落格後 覺得黑大的部落格寫得很棒啊 註解都寫得好詳細 很適合我這種沒有程度的人閱讀(黑大不用懷疑 我這種講法絕對是在表達很大的讚賞 哈哈) 謝謝黑大讓我能在你的部落格上講講話 謝謝!!

Post a comment