views:

215

answers:

2

Hi,

we have a WCF service hosted inside IIS. Now there are loads of different client applications calling this service. WS-SecureConversion is used.

Now, the service diagnostic log shows warnings that security sessions are being aborted. Most likely this is because of clients that do not properly close the session.

More info: the problem were "pending" security sessions. Those are sessions that were never used, only opened. This is pretty annoying as you can have a maximum of 128 such pending sessions before your services starts barfing 500s.

This can be easily reproduced (see answer below). I was able to query 128 SessionInitiationMessageHandlers using WinDbg. So this might be a good measure to identify this scenario.

Still, a way to identify those "misbehaving" clients would be useful.

Regards, Alex

+1  A: 

Since client and server share nothing but messages going between them, there's not much you can really do.

On the server side, you could look at some bits of information being sent from the client - check out the OperationContext.Current property in your service method - see the MSDN documentation on OperationContext about details what exactly is provided.

So you might be able to log certain information to identify the "offending" clients.

Marc

marc_s
The problem is to correlate that information:The WCF stack cancels the idling session. It has the information what client this session belongs to I assume. The logging is just bull.So let's say there is a client that just opened the channel, did its RST-SCT stuff and does nothing else. This will cause a pending security session being aborted and meanwhile the service is quite likely to run into "Server too busy 500's".What I am really confused about is that missing to close to client is a common mistake in WCF. So I would have assumed that there is a built in way to troubleshoot this.
Alex
@Alex: I highly doubt the WCF stack has any information about the client calling - it just knows it's a session and that session has an idle timeout, and when that idle timeout is reached, the session is simply cancelled - no interaction with the client happens, and no knowledge of the clients is necessary or present
marc_s
So you could lower the session timeout in your case, to eliminate any "lingering" sessions more quickly.
marc_s
Nice idea, about your question what information WCF stores for a session. Will dig into it a bit using WinDbg.Thanks for your replies so far!
Alex
One more comment: I completly agree with you. Proper timeouts should handle this. I guess a client shouldn't be able to tear down a server by its "misbehavour". However, we experience those 500s. We run default WCF timeout settings. The load of the server is something like 200 requests per second max. I wouldn't expect that it is so easy for some clients to take a WCF service down....
Alex
A: 

Sweet....the best way to kill a WCF service with a secure conversion seems to be to do nothing.

ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };

var client = new MyClient();
client.ClientCredentials.UserName.UserName = "user";
client.ClientCredentials.UserName.Password = "password";

while(true)
{
    Console.WriteLine("OPEN");
        var c = client.ChannelFactory.CreateChannel();
    ((ICommunicationObject)c).Open();

        // If I comment the following line, the service throws a 
        // "Too busy, too many pending sessions" 500.
        var request = new MyRequest { };
    c.Do(request);

        // Of course I did *not* comment this line
    ((ICommunicationObject)c).Close();
}

Meanwhile, this bug has been confirmed by MS and was solved in .NET 4.x:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=499859

Alex

related questions