I have a WCF Service hosted by IIS 7.5 with static variables in it.
The Service is called sporadical, and for a while the variables keep their values.
But at some time they lose the values and get re-initialized - and I don't know why.
First I thought that was because of the Application Pool recycling, so I changed the recycling interval to infinite - but it still happens.
I observed the w3wp.exe in task manager: It still has the same PID after the static variable reset happened, new calls to the service go to the same worker process - so we can exclude the app pool recycling, right?
So what happens there and how can I fix it, any ideas?
The Service uses
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
Here the results of several tests I made:
It even happens when I prevent a call from returning by Thread.Sleep(), so the idle timeout of the worker process (set to 20minutes) can be excluded as well? Sometimes it runs serveral hours before the reset of the statics take place.
But it seems the "old" waiting thread still exists because I can made it continue running by an external signal (SQL table entry that is being checked after X seconds between the sleeps in infinite loop).
Its like "another world" where the static variables still exist and the Threads keep on running, but each new call from a random time on runs in a new world with new variables...
Anyone a solution to this?
28 august 2014
No ideas to this thing?
Several tests show: There is not a real "reset" taking place but at some unknown/random time when I make a service call (for testing) the static constructor is being called and the static variables are set to their inital values. As if the application pool was recycled before. But it didn't - I observed the event log (Filter: Source "WAS") - no recycling.
What the hell is going on here?
Static members are actually per AppDomain, rather than per-thread or per-Application Pool. Off the top of my head I don't know how WAS creates AppDomains for hosting WCF service instances, and I'm not sure where I'd look to find out either, but it strikes me as something that WAS can do precisely what it likes with and is not meant to be relied upon.
I may add an edit later if I get around to doing some more research, as this is a somewhat interesting question. May I ask why you're using static variables? Sounds like asking for trouble, in my opinion.
Related
Error code:"
The request channel timed out while waiting for a reply after 00:09:59.6320000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding."
This error occurs infrequently when calling a Wcf service methods. It doesn't matter what method is. I have created test methods that returns simple strings. Sometimes it times out, sometimes it works perfectly. The strange thing is that when the WCF service is published on one server(for testing purposes)- there is no timeout. When I publish it on another server(live/public) there occurs these timeouts infrequently. I have set the timeout to 10 min as you could see above.
The webconfig setting should be correct, because it works for the one server. The only change made is the ip address. I know this is very difficult to answer and a bit ambiguous.
I'm sure this problem is too high level for me to solve, or maybe I'm making a simple mistake and it is too obvious for me to notice. If you could give me a pointer or just friendly advice on this problem I would really really appreciate it. I am shooting in the dark here. I thank you for your interest, proved by you reading up to here.
does it happen first time you call the service? if not, but does subsequently, it could be that the service instance has been locked by the calling thread - look into multiple instances or allowing concurrent use, obviously taking into account the thread safety requirements of your code
Hi have quite a problem with an Service running WCF in duplex-mode.
It leaks memory (not much but it's about 80MB a day) and after having a memory-profiler running alongside the service for 24 hours I found most of the memory sitting in byte[] referenced by quite a mess but I most references end in something like this:
and the "root" looks like this:
I too see lots of ServiceChannel (around 200) comming (I think) from the callback-channels.
I'm rather sure that I only hold 1 of those for each of the connected clients.
Overall my problem seems to be almost the same as this: memory leak in silverlight Wcf implementation but on the server-side.
I even tried the [MTAThread] thing mentioned here: WCF service leaks handles and memory when a client times out but it just don't solve the problem.
I just don't think that the problem is with my code as I wrap the callback-channels after getting it with OperationContext.Current.GetCallbackChannel<IServiceConnectorCallback>() in one of my own objects and those don't leak (there is only one of those for each clients in memory at any given snapshot) - sure I reset those callbacks on several occasions as the channel might change (clients losing the connection or reconnecting) but I don't have a way of disposing the old references so I only drop them and the GC should do it's job on them.
I do use PerCall on my service so I don't have any handle to those objects in my code at all.
I really have no clue at how I can handle this aside from restarting the service every few days - a solution I don't want to probose right now :(
So please give me some help/hints on this - thank you very much!
When a session based channel faults a call to Close will throw an exception. However, there are proxy side resources that are not cleaned up in this case and these are only cleaned up when you Abort the faulted channel
Make sure that when you replace a faulted channel that you Abort the old one first
i've tried to run mule on 3 cases in order to test it's mem usage:
One case is where i had a quartz generator create an event that a filter (right after it in a flow) allways stopped (Returned false) - meaning the flow did absolutly nothing.
In another case i did not use the filter but just used that flow to send a custom object to a WCF service running on another computer (using a cxf endpoint)
Also, i've checked what happened when i leave the flow as is but drop the wcf servce (meaning a lot of socket connection exceptions were thrown).
I did this because i am building a large app that would need this bus to work at all times (weeks at a time).
In all of those cases, the mem usage kept rising. (getting as high as 200mb ram after a few hours)
Any specific reasons this could happen?? What is causing mule to take more memory, in all of these cases?
Off the top of my head I'll stick with thread pool lazy initialization as explanation for this behavior. As time goes on and usage gets higher, the thread pools will get fully initialized.
If you want proof evidences take a look to this approach, or this one (with enableStatistics).
I've got a WCF service operation that just does a LINQ query on a SQL database, looking up 1 of 35 records that have a matching Guid (it's really as simple as it gets). When I call this method from a simple sandbox application, it comes back right away. However, when I have it running in a windows service, the first call to the method takes about 25 seconds (I take a timestamp before and after the call), and the second call (identical in every way to the first, made immediately after the first, just for testing purposes) comes back right away.
The call takes place inside of a ThreadPool.QueueUserWorkItem delegate, with other actions being performed before and after it, and it's the only thing in the entire delegate that is at all delayed.
Does the delay make sense, or is something going wrong here?.
Update:
I've confirmed that the problem isn't with the method itself. I called a completely different service method first, which had that delay, and the two calls to the original method just after both execute instantaneously. So it really is whatever the first call to the server is that's causing the problem.
In your case the first call will do 2 things:
JIT compile the service
Cache the query / data in the database server
This can explain the difference. On some systems the first call can timeout, while the second takes only one or two seconds.
One thing you might want to check is to see if your ASP.NET Worker Process that is hosting the service has an "idle timeout", it to me seems like it is the initial startup of ASP.net that might be causing your issue.
Have you tried enabling WCF tracing? Look for lags in the activity boundaries in the Process action activity.
I'd like to host a WCF web service in IIS. The service should keep a certain set of data all the time, it must never be lost.
My colleague told me this is impossible because IIS closes down the service after a certain time (I assume without any activity). Is that true? How do I prevent that behavior?
In case it matters, both IIS 6 and 7 are available.
By default, IIS recycles the worker process after a certain period of inactivity (20 mins if I recall correct). This causes your data to be lost.
You can turn off this behavior in the Properties page of the ApplicationPool under which your app is running.
EDIT: having said that, if it is really important that this data is never lost, I would consider storing it in a database or some other form of storage.
My colleague told me this is
impossible because IIS closes down the
service after a certain time (I assume
without any activity). Is that true?
How do I prevent that behavior?
This is true, but you can get around it by using an out of process state server.
Here are three links describing session state and how to set it up in IIS:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/0d9dc063-dc1a-46be-8e84-f05dbb402221.mspx?mfr=true
http://www.eggheadcafe.com/articles/20021016.asp
http://msdn.microsoft.com/en-us/library/ms178586.aspx