Opened 10 years ago

Closed 10 years ago

#2432 closed defect (fixed)

Subsequent calls to MaestroApi.HttpServerConnection.QueryFeatureSource timeout

Reported by: johngalambos Owned by: jng
Priority: low Milestone:
Component: Maestro Version: 2.5.0
Severity: minor Keywords:
Cc: External ID:

Description

If multiple calls are made in fairly quick succession to the MaestroApi.HttpServerConnection.QueryFeatureSource methods, beyond the second or third calls the methods don't return and eventually throw timeout exceptions. It looks like this is because the HttpWebResponse isn't disposed so the TCP connections from previous calls may be being help open longer than necessary and maxing out the default TCP connection limit.

Attachments (2)

HttpServerConnection.cs.patch (1.2 KB ) - added by johngalambos 10 years ago.
Patch for #2432
XmlReaderBase.cs.patch (618 bytes ) - added by johngalambos 10 years ago.
Follow-up patch for #2432

Download all attachments as: .zip

Change History (10)

by johngalambos, 10 years ago

Patch for #2432

comment:1 by jng, 10 years ago

I tried these two unit tests. A single-threaded one and a multi-threaded one. I cannot trigger the timeout exceptions. Do you have a reproducible sample?

[Test]
public void TestCase2432()
{
    var conn = CreateTestConnection();
    for (int i = 0; i < 10; i++)
    {
        using (var rdr1 = conn.FeatureService.QueryFeatureSource("Library://UnitTests/Data/Parcels.FeatureSource", "SHP_Schema:Parcels", "Autogenerated_SDF_ID < 20"))
        {
            while (rdr1.ReadNext()) { }
            rdr1.Close();
        }
    }
}
[Test]
public void TestCase2432()
{
    var conn = CreateTestConnection();
    var events = new List<ManualResetEvent>();
    for (int i = 0; i < 10; i++)
    {
        var resetEvent = new ManualResetEvent(false);
        ThreadPool.QueueUserWorkItem((args) =>
        {
            using (var rdr1 = conn.FeatureService.QueryFeatureSource("Library://UnitTests/Data/Parcels.FeatureSource", "SHP_Schema:Parcels", "Autogenerated_SDF_ID < 20"))
            {
                while (rdr1.ReadNext()) { }
                rdr1.Close();
                resetEvent.Set();
            }
        });
        events.Add(resetEvent);
    }
    WaitHandle.WaitAll(events.ToArray());
}

comment:2 by johngalambos, 10 years ago

Hi Jackie,

Thanks for the tests--they've helped me narrow it down. I'll submit tests with future patches. The timeout can be reproduced if you don't read all of the features in the feature reader:

     [Test]
        public void TestCase2432()
        {
            var conn = CreateTestConnection();
            for (int i = 0; i < 10; i++)
            {
                using (var rdr1 = conn.FeatureService.QueryFeatureSource("Library://UnitTests/Data/Parcels.FeatureSource", "SHP_Schema:Parcels", "Autogenerated_SDF_ID < 20"))
                {
                    var count = 0;
                    while (count < 5 && rdr1.ReadNext()) {
                        count++;
                    }
                    rdr1.Close();
                }
            }
        }

Which bring me to another question, but I'll ask it in the mailing list.

comment:3 by jng, 10 years ago

I have a fix on hand based on your provided test case.

comment:4 by jng, 10 years ago

Resolution: fixed
Status: newclosed

Fixed r8058. Thanks for the heads up.

comment:5 by johngalambos, 10 years ago

Resolution: fixed
Status: closedreopened

I'm going to reopen this as I think there is an issue with the fix.

It is possible for exceptions to be thrown in the constructor for XmlReaderBase (The InitProperties method inside the constructor does some validation on the XmlTextReader). If an exception is thrown the _resp field in XmlReadBase is not disposed. As a result if the constructor throws 2+ times, the timeout exceptions start to happen again on subsequent requests. There is a relevant stack overflow thread here: http://stackoverflow.com/questions/3825101/handling-idisposable-in-failed-initializer-or-constructor.

Specifically, I'm seeing the following exception being thrown in the Initproperties method for a couple of feature sources. System.Exception: Bad document. Expected element: xs:schema. I think this is due to an empty result set, not necessarily a corrupt response.

comment:6 by johngalambos, 10 years ago

Just an update to my previous comment, the bad document exceptions I'm seeing do look like they are due to unexpected response xml not an empty result set. I still think this fix is still worth implementing.

by johngalambos, 10 years ago

Attachment: XmlReaderBase.cs.patch added

Follow-up patch for #2432

comment:7 by johngalambos, 10 years ago

I've attached a patch that I think is a clean way to resolve this issue. Sorry for lack of a test at this point , but I'm not sure how to get that constructor to throw with the existing test data / integration tests.

I ran into this issue by attempting to a query an extended/joined feature class. The resulting xml FeatureSet element that does not contain an xs:schema element. This triggers the exception within the XmlReaderBase constructor.

comment:8 by jng, 10 years ago

Resolution: fixed
Status: reopenedclosed

Fixed r8086. Thanks for the patch.

Note: See TracTickets for help on using tickets.