locked
Possible issue - Listener Reply

    Question

  • Hi,

    I'm developing a listener application and I found a possible issue. 

    In this new version, when the program takes long to reply, I receive the message: (1113) - Error converting string to wstring. After this, the application crashes.

    In the previous version, I received the message: (64) - The specified network name is no longer available, and then the program continued working fine.

    Is there any way to prevent this crash?


    Here goes the code:

    // Starts the Http Listener Server
    http::listener::http_listener::create(this->_url, 
    	[=](http::http_request message)
    	{
    		http::json::value::field_map fieldMap;
    
    		fieldMap.insert(std::make_pair(L"Description", http::json::value::string(this->_description)));
    		fieldMap.insert(std::make_pair(L"Name"       , http::json::value::string(this->_name       )));
    		fieldMap.insert(std::make_pair(L"HostName"   , http::json::value::string(this->_hostname   )));
    		fieldMap.insert(std::make_pair(L"Version"    , http::json::value::string(this->_version    )));
    		fieldMap.insert(std::make_pair(L"Url"        , http::json::value::string(this->_url        )));
    		fieldMap.insert(std::make_pair(L"Location"   , http::json::value::string(this->_location   )));
    		fieldMap.insert(std::make_pair(L"OSVersion"  , http::json::value::string(this->_osVersion  )));
    		fieldMap.insert(std::make_pair(L"Processors" , http::json::value::string(this->_processors )));
    
    		http::json::value jsonFields = http::json::value::object(fieldMap);
    		message.reply(http::status_codes::OK, jsonFields); // SOMETIMES IT RAISES AN EXCEPTION
    
    		fieldMap.clear();
    	}
    ).listen([]() { fgetc(stdin); }).wait();

    Call Stack:

    Stack Trace


    Marcelo



    Monday, October 15, 2012 8:29 PM

Answers

  • Hi Marcelo,

    Ok I'm not able to repro it, but I found a place where we are doing an incorrectly treating an ANSI string as UTF-8. I can repro the connection being terminated, but the string conversion succeeds. I have filed a bug and we will fix this for our next fresh on the internal bits.

    Sorry unfortunately I can't give you a workaround until then :(

    Our refresh should come in the next 2 weeks.

    Steve


    Monday, October 22, 2012 10:51 PM

All replies

  • Hi Marcelo I'm taking a look at this now and will get back to you.
    Tuesday, October 16, 2012 12:54 AM
  • Thanks Steve.


    Additional information:
    The previous version causes memory leaks while replying.
    The current version doesn't, and it is pretty much better. Nice job.


    Marcelo


    Thursday, October 18, 2012 9:35 PM
  • Hi Marcelo,

    I have been trying to reproduce this with no luck. Just to clarify here there is no exception coming out of the message.reply(...) call right? It is asynchronous and returns a task immediately.

    I believe there are two issues going on here, first you are getting the underlying connection closed for some reason, then when trying to report the error about the connection being closed another error occurs about a string conversion. Let's focus on the first issue about the network no longer avaliable. From the sounds of this the HTTP client could be closing the connection before all the data from the response is being sent.

    You mention this occurs when the program takes a long time to reply. Looking at your code in your request handler on the listener not much is going on inside. All that is being done is creating a JSON object. How long is a 'long' time? Is there any way you can share with me the HTTP client side code being used, is it written in Casablanca as well?

    Thanks, Steve

    Friday, October 19, 2012 12:53 AM
  • Hi Steves,

    Sorry about saying that the program takes long to reply. I thought the issue was related with timeout or something. But it is not. Although it is still occuring when the client closes the connection before we send the reply.

    It can be reproduced in Internet Explorer 9 and Chrome 22.0.1229.94 m by closing the page.

    Here are the steps I have made:

    1) Place a breakpoint at the 'message.reply' line;
    2) Open the browser and invoke the casablanca listener URL;
    3) Close the browser; 
    4) Release the breakpoint.

    The error (1113) - Error converting string to wstring come from the actors::log and after that the app crashes.

    Depending on the browser the crash differs:

    IE9: Listener.exe has triggered a breakpoint.
    Chrome: Unhandled exception at at 0x000007FEFE14CACD in Listener.exe: Microsoft C++ exception: utilities::win32_exception at memory location 0x00000000010AF090.

    My client side isn't in Casablanca. The only thing I know is that it was developed in C#.NET 4.0, but I don't have the source code

    Like you said, I think that it is a string conversion error when trying to report the error about the connection being closed.


    Marcelo






    Friday, October 19, 2012 4:09 PM
  • Hi Marcelo,

    Ok I'm not able to repro it, but I found a place where we are doing an incorrectly treating an ANSI string as UTF-8. I can repro the connection being terminated, but the string conversion succeeds. I have filed a bug and we will fix this for our next fresh on the internal bits.

    Sorry unfortunately I can't give you a workaround until then :(

    Our refresh should come in the next 2 weeks.

    Steve


    Monday, October 22, 2012 10:51 PM
  • OK Steve, I'll wait for the next refresh.

    Thanks for the help.



    Marcelo

    Wednesday, October 24, 2012 2:10 PM
  • Hi Marcelo,

    Can you try this out again now with our latest refresh to see if the problem has been addressed?

    Thanks, Steve

    Tuesday, November 13, 2012 10:32 PM
  • Hi Steves,

    When the situation occurs, the app reports the message Error 1229: Error sending http response (HttpSendResponseEntityBody): An operation was attempted on a nonexistent network connection.

    After that, the app continue working with no problem.
    The issue is solved.
    Thanks. Great job.


    Marcelo

    Wednesday, November 14, 2012 4:11 PM
  • Hi Marcelo,

    Great to hear the fix worked! Let us know if you have any other problems or feedback.

    Steve

    Wednesday, November 14, 2012 6:51 PM