2013-04-01 1069 views
1

無論何時部署我們的組件,我們都會收到以下異常。有時組件本身不會啓動,有時服務控制檯可能會啓動,但服務不會處理任何消息。 錯誤非常簡單。還有一個HttpListener仍在監聽前綴。System.Net.HttpListenerException:無法偵聽前綴'xxxx',因爲它與機器上現有的註冊衝突

NServiceBus.Hosting.GenericHost System.Exception: Failed to start listener for http://localhost/products/ make sure that you have admin priviliges ---> System.Net.HttpListenerException: Failed to listen on prefix 'http://localhost:80/products/' because it conflicts with an existing registration on the machine. 
    at System.Net.HttpListener.AddAllPrefixes() 
    at System.Net.HttpListener.Start() 
    at NServiceBus.Gateway.Channels.Http.HttpChannelReceiver.Start(String address, Int32 numWorkerThreads) in c:\BuildAgent\work\nsb.master_6\src\gateway\NServiceBus.Gateway\Channels\Http\HttpChannelReceiver.cs:line 30 
    --- End of inner exception stack trace --- 
    at NServiceBus.Gateway.Channels.Http.HttpChannelReceiver.Start(String address, Int32 numWorkerThreads) in c:\BuildAgent\work\nsb.master_6\src\gateway\NServiceBus.Gateway\Channels\Http\HttpChannelReceiver.cs:line 37 
    at NServiceBus.Gateway.Receiving.GatewayReceiver.Start(Address localAddress) in c:\BuildAgent\work\nsb.master_6\src\gateway\NServiceBus.Gateway\Receiving\GatewayReceiver.cs:line 38 
    at System.Collections.Generic.List`1.ForEach(Action`1 action) 
    at NServiceBus.Unicast.UnicastBus.NServiceBus.IStartableBus.Start(Action startupAction) in c:\BuildAgent\work\nsb.master_6\src\unicast\NServiceBus.Unicast\UnicastBus.cs:line 867 
    at NServiceBus.Hosting.GenericHost.Start() in c:\BuildAgent\work\nsb.master_6\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 34 

當我們進行深度分析。

  1. 當您運行NServiceBus.Master 簡介
  2. 這個問題只在發生,只要您從服務控制檯執行重新啓動服務這個問題只在發生
  3. 沒有不管你有多少WorkerThreads運行

當我們更深入地讀取NSB代碼時,我們發現HttpListener在對象Dispose期間被關閉,這令我們感到困惑。除此之外,當你停止服務時,整個進程本身就會被終止,所以機器上不會有任何對象來監聽給定的URL前綴。但是,我們錯了。當我們分析很多閉包時,我們發現NServinceBus.Host進程仍然在運行,即使Service-Console認爲服務已經停止。每當我們停止服務控制檯上的服務時,進程在機器上仍然活動&完全關閉需要相當長的時間。因此,當我們執行重新啓動時,當前服務有一個以上的進程實例 - 嘗試啓動另一個實例仍然試圖停止。我們確認重啓過程會拋出上述異常。

我們把關閉過程的轉儲。我們發現,雖然服務控制檯顯示狀態爲已停止,但後臺線程仍處於活動狀態。 Dispose期間有很多鎖/ ObjWait。肯定已停止的服務尚未關閉HttpListener對象。

 Child SP    IP Call Site 
000000001f19e048 00000000778818ca [GCFrame: 000000001f19e048] 
000000001f19e118 00000000778818ca [HelperMethodFrame_1OBJ: 000000001f19e118] System.Threading.Monitor.ObjWait(Boolean, Int32, System.Object) 
000000001f19e230 000007fe99d57ccb System.Transactions.CommittableTransaction.Commit() 
000000001f19e2d0 000007fe99d577df System.Transactions.TransactionScope.InternalDispose() 
000000001f19e3c0 000007fe99d56f1c System.Transactions.TransactionScope.Dispose() 
000000001f19e590 000007fe99c4a3b5 NServiceBus.Utils.TransactionWrapper.RunInTransaction(System.Action, System.Transactions.IsolationLevel, System.TimeSpan) 
000000001f19e610 000007fe99c45b2b NServiceBus.Unicast.Transport.Transactional.TransactionalTransport.Process() 
000000001f19e680 000007fe99c455cb NServiceBus.Utils.WorkerThread.Loop() 
000000001f19e6d0 000007fef6fdf8a5 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
000000001f19e830 000007fef6fdf609 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
000000001f19e860 000007fef6fdf5c7 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
000000001f19e8b0 000007fef6ff2d21 System.Threading.ThreadHelper.ThreadStart() 
000000001f19ebc8 000007fef81cf713 [GCFrame: 000000001f19ebc8] 
000000001f19eef8 000007fef81cf713 [DebuggerU2MCatchHandlerFrame: 000000001f19eef8] 
000000001f19f0d8 000007fef81cf713 [ContextTransitionFrame: 000000001f19f0d8] 
000000001f19f2c8 000007fef81cf713 [DebuggerU2MCatchHandlerFrame: 000000001f19f2c8] 

我們發現,在HttpListener活躍&傾聽。

 Child SP    IP Call Site 
000000002038e2f8 000000007788135a [InlinedCallFrame: 000000002038e2f8] System.Net.UnsafeNclNativeMethods+HttpApi.HttpReceiveHttpRequest(System.Runtime.InteropServices.CriticalHandle, UInt64, UInt32, HTTP_REQUEST*, UInt32, UInt32*, System.Threading.NativeOverlapped*) 
000000002038e2f8 000007fe99c6a2f8 [InlinedCallFrame: 000000002038e2f8] System.Net.UnsafeNclNativeMethods+HttpApi.HttpReceiveHttpRequest(System.Runtime.InteropServices.CriticalHandle, UInt64, UInt32, HTTP_REQUEST*, UInt32, UInt32*, System.Threading.NativeOverlapped*) 
000000002038e2b0 000007fe99c6a2f8 DomainBoundILStubClass.IL_STUB_PInvoke(System.Runtime.InteropServices.CriticalHandle, UInt64, UInt32, HTTP_REQUEST*, UInt32, UInt32*, System.Threading.NativeOverlapped*) 
000000002038e3b0 000007fe99c697a4 System.Net.HttpListener.GetContext() 
000000002038e4d0 000007fe99c6924f NServiceBus.Gateway.Channels.Http.HttpChannelReceiver.HttpServer() 
000000002038e530 000007fef6fdf8a5 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
000000002038e690 000007fef6fdf609 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
000000002038e6c0 000007fef6fdf5c7 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 
000000002038e710 000007fef6ff2d21 System.Threading.ThreadHelper.ThreadStart() 
000000002038ea28 000007fef81cf713 [GCFrame: 000000002038ea28] 
000000002038ed58 000007fef81cf713 [DebuggerU2MCatchHandlerFrame: 000000002038ed58] 
000000002038ef38 000007fef81cf713 [ContextTransitionFrame: 000000002038ef38] 
000000002038f128 000007fef81cf713 [DebuggerU2MCatchHandlerFrame: 000000002038f128] 

問題: 爲什麼服務控制檯報告該服務被停止,儘管過程還是機器

注意主動:重現此問題,您必須安裝您的主機作爲使用NServiceBus.Master配置文件的Windows服務並嘗試重新啓動服務,則可能需要更多嘗試來解決此問題。

更新:

當我讀到NSB代碼,在HttpChannelReceiver.Start(),它開始在新線程監聽器。

  1. 此監聽線程是前臺線程。 (所有其他工作線程都是BG線程)
  2. 沒有停止信號去這個前臺線程
  3. 沒有變量/字段持有此線程的引用 - 中止是不可能的。

當ServiceHost殺死當前進程的內存時,這個監聽線程纔會被回收,直到ServicHost收集它,這個線程將被阻止退出當前進程。

+0

我創建了NSB問題這一點。 https://github.com/NServiceBus/NServiceBus/issues/1083 –

回答

相關問題