AddressAlreadyInUseException
- I have a simple application that listens on the .NET Servicebus. All works fine 99% of the time but on occasion when opening the serivce host I get an AlreadyInUseException. I'm using a NetTCPRelayBinding in hybird mode. When this happens I can stop my app, restart and all if fine.
What I'm looking for a way to debug this. I can watch the addresses/ports with NetStat, CurrPorts, or TCPView but I don't see anythign unusual, then again I'm not sure I'd recognized something unusual.
Has anyone seen this problem?
Does anyone know how to get the port that the ServiceHost.Open is attempting to use?
Is there any information in the ServiceHost object that can tell me more about the addressinuse error?
How about something in the exception?
Is there a way in the exception to clean up this error?
Any help would be greatly appreciated.
--Huli
Answers
- If you have shutdown the application properly, you should not encounter this problem... Can you please make sure no other application is using the endpoint? Try to put a public ServiceRegistrySettings behavior, so that once the service is opened, you'll be able to see it on the service registry. Now if you close the application, and refresh the registry page, do you still see the endpoint there?
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byYi-Lun LuoMSFT, ModeratorFriday, October 30, 2009 9:50 AM
All Replies
- Hello, after you shutdown your service host, it may take a few seconds before the address is available again. How long have you waited before trying to start the host again? Also, the way you shutdown your service may have an impact on this issue. If you call ServiceHost.Close() manually, the channel will notify Service Bus to remove the endpoint address. However, if you simply close the application without shutdown, it may take some time for the Service Bus to be aware of the service no longer exists.
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights. - Thanks for your reply.
We wait 1 minute before trying to create the listener again. Based on your reply this is more than enough time for service bus to clean up the endpoint. We will bump this up to 5 minutes and see what happens.
As far as shutdown goes we always call Close(), if it fails we call Abort() and then shutdown the app.
Our problem isn't at shutdown. Shutting down always clears the problem, it's runtime that seems to be the root of the problem. Here is how the problem manifests itself.
1.) start app - hasn't been run in hours
2.) open service host
3.) get AddressAlreadInUseException - Call Abort in the exception handler, we've also handled this error without the abort. We've also tried the Close() method before the Abort.
4.) wait 1 minute and repeat from step 2 - once we get that 1st AddressAlreadyInUseException we keep getting it
5.) after watching this fail N times (I've watched it fail for over an hour) I turn off the app. Start the app and the problem goes away
Like I said this problem is very difficult to reproduce consistently happens infrequently. We added code to catch(Exception) and log any errors we might get before the AddressAlreadyInUse but we haven't seen any previous exceptions.
Can you recommend any tools to help me gather more information to debug thsi problem? - If you have shutdown the application properly, you should not encounter this problem... Can you please make sure no other application is using the endpoint? Try to put a public ServiceRegistrySettings behavior, so that once the service is opened, you'll be able to see it on the service registry. Now if you close the application, and refresh the registry page, do you still see the endpoint there?
Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.- Marked As Answer byYi-Lun LuoMSFT, ModeratorFriday, October 30, 2009 9:50 AM
I have the public ServiceRegistrySettings behavior. I have a machine currently throwing the AddressAlreadyInUseException, when I check the registry page the address is not displayed. This is a machine that I just rebooted and then started my application. Now, when I shutdown my app and restart everything is fine. Shutdown definitely cleans up the problem. The problem appears to be in the servicehost open method.


