microsoft / cpprestsdk

The C++ REST SDK is a Microsoft project for cloud-based client-server communication in native code using a modern asynchronous C++ API design. This project aims to help C++ developers connect to and interact with services.
Other
8.01k stars 1.66k forks source link

Exception while closing http_listener when compiled with CPPREST_HTTP_LISTENER_IMPL = asio #1622

Open CatrinBusley opened 3 years ago

CatrinBusley commented 3 years ago

We want to use the cpprestsdk with the boost implementation on windows and linux. So we compiled the current ressources with the cmake-flag CPPREST_HTTP_LISTENER_IMPL = asio. With this binary we get an access viloation exception while closing the http_listener. This exception doesn't occur when we compile with CPPREST_HTTP_LISTENER_IMPL = httpsys.

Can be reproduced with the following code:

#include <cpprest/http_listener.h>
#include <cpprest/uri.h>

#include <stdio.h>

using namespace utility;
using namespace web::http;
using namespace web::http::experimental::listener;

class Http_RestServer
{
public:
  Http_RestServer() = default;
  Http_RestServer(string_t const& url);

  pplx::task<void> Open();
  pplx::task<void> Close();

  http_listener m_listener;

};

Http_RestServer::Http_RestServer(string_t const& url) : m_listener(url)
{
}

pplx::task<void> Http_RestServer::Open()
{
  return m_listener.open();
}

pplx::task<void> Http_RestServer::Close()
{
  return m_listener.close();
}

int main()
{
  Http_RestServer server(U("http://0.0.0.0:10000"));
  server.Open().wait();

  printf("Press ENTER to exit\n");

  getchar();
  server.Close().wait();

  return 0;
}

Stack trace output:

>   Test_CppRestServer.exe!std::_Ref_count_base::_Incref() Line 882 C++ Non-user code. Symbols loaded.
    Test_CppRestServer.exe!std::_Ptr_base<Concurrency::details::_Task_impl<unsigned char> >::_Copy_construct_from<Concurrency::details::_Task_impl<unsigned char> >(const std::shared_ptr<Concurrency::details::_Task_impl<unsigned char> > & _Other) Line 1131 C++ Non-user code. Symbols loaded.
    Test_CppRestServer.exe!std::shared_ptr<Concurrency::details::_Task_impl<unsigned char> >::shared_ptr<Concurrency::details::_Task_impl<unsigned char> >(const std::shared_ptr<Concurrency::details::_Task_impl<unsigned char> > & _Other) Line 1392  C++ Non-user code. Symbols loaded.
    Test_CppRestServer.exe!Concurrency::task<unsigned char>::task<unsigned char>(const Concurrency::task<unsigned char> & _Other) Line 3039 C++ Non-user code. Symbols loaded.
    Test_CppRestServer.exe!Concurrency::task<void>::task<void>(const Concurrency::task<void> & _Other) Line 4005    C++ Non-user code. Symbols loaded.
    Test_CppRestServer.exe!web::http::experimental::listener::details::http_listener_impl::close() Line 98  C++ Symbols loaded.
    Test_CppRestServer.exe!web::http::experimental::listener::http_listener::close() Line 279   C++ Symbols loaded.
    Test_CppRestServer.exe!Http_RestServer::Close() Line 34 C++ Symbols loaded.
    Test_CppRestServer.exe!main() Line 45   C++ Symbols loaded.
    [External Code]     Annotated Frame

Exception thrown: read access violation.
**this** was 0xFFFFFFFFFFFFFFF7.

Maybe this is related to issue #1366

Any help to fix or workaroud this issue would be appreciated. Thanks, Catrin