Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IStreamingListener.Start() hangs for indefinite time #23

Closed
mrdavidlaing opened this issue Mar 7, 2011 · 4 comments
Closed

IStreamingListener.Start() hangs for indefinite time #23

mrdavidlaing opened this issue Mar 7, 2011 · 4 comments

Comments

@mrdavidlaing
Copy link
Contributor

http://faq.labs.cityindex.com/questions/istreaminglistener-start-hangs-for-indefinite-time

@artiz
Copy link

artiz commented Aug 5, 2011

Hello, I am using CIAPI.CS in WPF application and found th same issue (IStreamingListener.Start() frozen).
I have found that listener hangs when I have added second Adapter set to LightstreamerClient.GetAdapterList().

It can be done by following smd.js modification:

"Prices": {
                    "description": "Stream of current prices. Try PRICES.PRICE.154297 (GBP/USD (per 0.0001) CFD) which prices Mon - Fri 24hrs",
                    "target": "CITYINDEXSTREAMING",
                    "channel": "PRICES.PRICE.{marketIds}",
                    "transport": "HTTP",
                    "protocol": "lightstreamer-3.6",
                    "returns": {
                        "$ref": "PriceDTO"
                    },
                    "group": "Streaming API",
                    "parameters": [
            {
                "type": "array",
                "items": [
                {
                    "type": "integer"
                }
              ],
                "name": "marketIds",
                "description": "The marketIds",
                "demoValue": "[71442, 71443]"
            }
          ]
                },

                "ClientAccountMargin": {
                    "description": "Retrieve client account information",
                    "target": "STREAMINGCLIENTACCOUNT",
                    "channel": "CLIENTACCOUNTMARGIN",
                    "transport": "HTTP",
                    "protocol": "lightstreamer-3.6",
                    "returns": {
                        "$ref": "ClientAccountMarginDTO"
                    },
                    "group": "Streaming API"
                }

"ClientAccountMargin" section added by me.

After that I have modified Unit Test in StreamingClientTests:

public const string TestUsername = "*********";
        public const string TestPassword = "*********";
        public const string TestTradingApiUri = "https://ciapi.cityindex.com/tradingapi/";
        public const string TestStreaminUri = "https://push.cityindex.com/";

        private ManualResetEvent _pricesDataLoadedEvent = new ManualResetEvent(false);
        private ManualResetEvent _newsDataLoadedEvent = new ManualResetEvent(false);

        private IStreamingClient _streamingClient;
        private CIAPI.Rpc.Client _rpcClient;

        [SetUp]
        public void SetUp()
        {
            _rpcClient = new CIAPI.Rpc.Client(new Uri(TestTradingApiUri));
            _rpcClient.LogIn(TestUsername, TestPassword);

            _streamingClient = StreamingClientFactory.CreateStreamingClient(
                new Uri(TestStreaminUri),
                TestUsername,
                _rpcClient.SessionId);
        }

        [Test]
        public void SubscribingPricesTopic()
        {
            _streamingClient.Connect();
            
            var marketIds = new[] { 400481119, 400490176, 400481120, 400490174 };
            
            var pricesListener = _streamingClient.BuildPricesListener(marketIds);
            pricesListener.MessageReceived += listener_PricesReceived;
            pricesListener.Start();

            var accountListener = _streamingClient.BuildClientAccountMarginListener();
            accountListener.MessageReceived += listener_AccountInfoReceived;
            accountListener.Start();

            var handles = new WaitHandle[] { _pricesDataLoadedEvent, _newsDataLoadedEvent };
            var receved = WaitHandle.WaitAny(handles, 30000);
            Assert.IsTrue(receved != WaitHandle.WaitTimeout, "No Account Info/Prices loaded");
        }

        private void listener_PricesReceived(object sender, MessageEventArgs e)
        {
            _pricesDataLoadedEvent.Set();
        }

        private void listener_AccountInfoReceived(object sender, MessageEventArgs e)
        {
            _newsDataLoadedEvent.Set();
        }

And at UT run process hangs on pricesListener.Start() line.

So I have a question - are parallel connections to different adapters set supported by LightstreamerClient?
If not - how I should implement Prices and Account info data streaming, should I use two CIAPI.Rpc.Client instances?

@mrdavidlaing
Copy link
Contributor Author

In your case, I suspect you are running into the .NET framework's built in max concurrent HTTP connections limit.

Have you tried adding:

<system.net>
    <connectionManagement>
      <add address = "*" maxconnection = "100" />
    </connectionManagement>
 </system.net>

to your App.Config?

@artiz
Copy link

artiz commented Aug 5, 2011

I did it from code:

ServicePointManager.ServerCertificateValidationCallback += ValidateCertificate;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.DefaultConnectionLimit = 500;

Now I faced new problem: "The request was aborted: Could not create SSL/TLS secure channel." exception thrown at connecting to Lightstreaming server (https://push.cityindex.com/).

An this error is shown only wehn I use CIAPI from WPF application, UT works fine. I have collected network log as described there: http://blogs.msdn.com/b/asiatech/archive/2009/04/08/using-system-net-trace-to-troubleshooting-ssl-problem-in-net-2-0-application.aspx

System.Net.Sockets Verbose: 0 : [9060] Data from Socket#62955487::PostCompletion
System.Net.Sockets Verbose: 0 : [9060] 00000000 : 02 00 00 46 03 01 4E 3C-10 64 6F 3C C7 AB 5A 94 : ...F..N<.do<..Z.
System.Net.Sockets Verbose: 0 : [9060] 00000010 : 00 90 5E 68 2A AF 2F EE-0E 90 B8 50 79 11 7D 8B : ..^h*./....Py.}.
System.Net.Sockets Verbose: 0 : [9060] 00000020 : 34 93 CB E7 47 2E 20 4E-3C 10 3D 88 9A D8 A8 3A : 4...G. N<.=....:
System.Net.Sockets Verbose: 0 : [9060] 00000030 : 17 0D 95 8A 22 B9 1F 84-0F 78 66 D4 67 33 87 7A : ...."....xf.g3.z
System.Net.Sockets Verbose: 0 : [9060] 00000040 : B7 96 69 1C C9 08 0A 00-2F 00                   : ..i...../.
System.Net.Sockets Verbose: 0 : [9060] Socket#62955487::EndReceive(OverlappedAsyncResult#33592719)
System.Net.Sockets Verbose: 0 : [9060] Exiting Socket#62955487::EndReceive()    -> 74#74
System.Net Information: 0 : [9060] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = a:0, targetName = push.cityindex.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [9060] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=IncompleteMessage).
System.Net.Sockets Verbose: 0 : [9060] Socket#62955487::Dispose()
System.Net Error: 0 : [9060] Exception in the HttpWebRequest#17561922:: - The request was aborted: Could not create SSL/TLS secure channel.
System.Net Verbose: 0 : [9060] HttpWebRequest#17561922::EndGetResponse()
System.Net Error: 0 : [9060] Exception in the HttpWebRequest#17561922::EndGetResponse - The request was aborted: Could not create SSL/TLS secure channel.

But Google does not know anyting about "returned code=IncompleteMessage".
Have you seen errors like this?

WPF app uses the same assemblies as UT and both od them compiled against .NET 4.0.

@mrdavidlaing
Copy link
Contributor Author

I haven't seen that before; my only guess is that your ssl settings are incompatible with the Java based Lightstreamer server.

Try open https://push.cityindex.com in a browser and explore the details of the SSL cert.

Perhaps you need to use:

  ServicePointManager.SecurityProtocol= SecurityProtocolType.Ssl3|SecurityProtocolType.Tls;

Looking at the way my browser (Chrome on Mac) is connecting:

<img src=http://content.screencast.com/users/mrdavidlaing/folders/Jing/media/a75d107a-fe7b-4bb4-aa30-1534fae308d9/00000078.png">

More details at: http://support.microsoft.com/kb/915599

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants