title: Boost ASIO system error 995: The I/O operation has been aborted
body: <p>I am trying to write a simple server that allows multiple clients to connect.  When I run my program, I get the following error as output:</p>
  
  <pre><code>[3730] Press [return] to exit.
  Listening on: 127.0.0.1:7777
  [5d0] Thread Start
  Error: system:995 The I/O operation has been aborted because of either a 
  thread exit or an application request
  </code></pre>
  
  <p>I think this is because my Client object is falling out of scope, but I'm not entirely sure if this is actually the problem or if there's something else wrong with my code.  </p>
  
  <pre><code>ClientNetwork::ClientNetwork(asio::io_service&amp; ios, const asio::ip::tcp::endpoint&amp; edp) : mIOService(ios), mAcceptor(ios, edp)
  {
      /*mAcceptor.open(edp.protocol());
      mAcceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(false));*/
      listen();
  }
  ClientNetwork::~ClientNetwork()
  {
      boost::system::error_code ec;
      mAcceptor.close(ec);
  
      mConnectionThreads.join_all();
      mClients.clear();
      std::cout &lt;&lt; "KILLING NETWORK" &lt;&lt; std::endl;
  }
  void ClientNetwork::listen()
  {
      mConnectionThreads.create_thread(boost::bind(&amp;ClientNetwork::connectionThread, this));
      Client* c = new Client(mIOService);
      mAcceptor.listen(boost::asio::socket_base::max_connections);
      mAcceptor.async_accept(*c-&gt;getSocket(), boost::bind(&amp;ClientNetwork::handleAccept, this, _1, c));
  
  }
  
  void ClientNetwork::handleAccept(const boost::system::error_code&amp; error, Client* client)
  {
  
      if (!error)
      {
          mClients.push_back(client);
          mConnectionThreads.create_thread(boost::bind(&amp;ClientNetwork::connectionThread, this));
          std::cout &lt;&lt; mConnectionThreads.size() &lt;&lt; std::endl;
      }
      else
      {
          std::cout &lt;&lt; "Error: " &lt;&lt; error &lt;&lt; " " &lt;&lt; error.message() &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>This is my main (not sure it's entirely helpful but felt it would be good to include:</p>
  
  <pre><code>int main(int argc, char * argv[])
  {
      boost::shared_ptr&lt; boost::asio::io_service &gt; io_service(
          new boost::asio::io_service
      );
      boost::shared_ptr&lt; boost::asio::io_service::work &gt; work(
          new boost::asio::io_service::work(*io_service)
      );
      boost::shared_ptr&lt; boost::asio::io_service::strand &gt; strand(
          new boost::asio::io_service::strand(*io_service)
      );
      global_stream_lock.lock();
      std::cout &lt;&lt; "[" &lt;&lt; boost::this_thread::get_id()
          &lt;&lt; "] Press [return] to exit." &lt;&lt; std::endl;
      global_stream_lock.unlock();
  
      /*boost::thread_group worker_threads;
      for (int x = 0; x &lt; 2; ++x)
      {
          worker_threads.create_thread(boost::bind(&amp;WorkerThread, io_service));
      }*/
  
      /*boost::shared_ptr&lt; boost::asio::ip::tcp::acceptor &gt; acceptor(
          new boost::asio::ip::tcp::acceptor(*io_service)
      );
      boost::shared_ptr&lt; boost::asio::ip::tcp::socket &gt; sock(
          new boost::asio::ip::tcp::socket(*io_service)
      );*/
  
      try
      {
          boost::asio::ip::tcp::resolver resolver(*io_service);
          boost::asio::ip::tcp::resolver::query query(
              "127.0.0.1",
              boost::lexical_cast&lt; std::string &gt;(7777)
          );
          boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
  
  
  
          ClientNetwork clientNet(*io_service, endpoint);
  
          global_stream_lock.lock();
          std::cout &lt;&lt; "Listening on: " &lt;&lt; endpoint &lt;&lt; std::endl;
          global_stream_lock.unlock();
      }
      catch (std::exception &amp; ex)
      {
          global_stream_lock.lock();
          std::cout &lt;&lt; "[" &lt;&lt; boost::this_thread::get_id()
              &lt;&lt; "] Exception: " &lt;&lt; ex.what() &lt;&lt; std::endl;
          global_stream_lock.unlock();
      }
  
      std::cin.get();
  
      //worker_threads.join_all();
  
      return 0;
  }
  </code></pre>