title: boost asio "A non-recoverable error occurred during database lookup"
body: <p>I'm currently stress testing my server.</p>
  
  <p>sometimes I get "A non-recoverable error occurred during database lookup" Error
  coming from <strong>error.message()</strong></p>
  
  <p>error is sent to my handling function by <strong>boost::asio::placeholders::error</strong> called on the <strong>async_read method</strong>.</p>
  
  <p>I have no idea what this error means, and I am not able to reproduce purposely this error, it only happen sometimes and seems to be random (of course it is not, but it seems)</p>
  
  <p>Does anyone have ever got this error message, and if so, know where it came from ?</p>
  
  <hr>
  
  <h2>EDIT 1</h2>
  
  <p>Here's what I found on the boost library, the error is :</p>
  
  <p><strong>no_recovery = BOOST_ASIO_NETDB_ERROR(NO_RECOVERY)</strong></p>
  
  <p>But can't figure out what this is...</p>
  
  <hr>
  
  <h2>EDIT 2</h2>
  
  <p>Just so you know everything about my problem, here the design : </p>
  
  <p>I have only one io_service.
  Everytime a user is connecting, an async_read is starting, waiting for something to read.
  When it reads something, most of the time, it is doing some work on a thread (coming from a pool), and write something synchronously back to the user. (using boost write).
  Even since boost 1.37 claims that synchronous write is thread safe, I'm really worried about the fact that it is coming from this.</p>
  
  <p>If the user sends different message really quick, it can happen that async_read and write are called simultaneously, can it does any harm ?</p>
  
  <hr>
  
  <h2>EDIT 3</h2>
  
  <p>Here's some portion of my code asked by Dave S :</p>
  
  <pre><code>    void TCPConnection::listenForCMD() {
      boost::asio::async_read(m_socket,
                              boost::asio::buffer(m_inbound_data, 3),
                              boost::asio::transfer_at_least(3),
                              boost::bind(&amp;TCPConnection::handle_cmd,
                                          shared_from_this(),
                                          boost::asio::placeholders::error)
                              );
    }
  
        void TCPConnection::handle_cmd(const boost::system::error_code&amp; error) {
          if (error) {
            std::cout &lt;&lt; "ERROR READING : " &lt;&lt; error.message() &lt;&lt; std::endl;
      return;
          }                                                                                                                                                                                                                              
            std::string str1(m_inbound_data);
            std::string str = str1.substr(0,3);
  
            std::cout &lt;&lt; "COMMAND FUNCTION: " &lt;&lt; str &lt;&lt; std::endl;
  
            a_fact func = CommandFactory::getInstance()-&gt;getFunction(str);
  
            if (func == NULL) {
              std::cout &lt;&lt; "command doesn't exist: " &lt;&lt; str &lt;&lt; std::endl;
              return;
            }
  
            protocol::in::Command::pointer cmd = func(m_socket, client);
  
            cmd-&gt;setCallback(boost::bind(&amp;TCPConnection::command_is_done,
                                         shared_from_this()));
            cmd-&gt;parse();                                                                                                                                                                                                                                   
        }
  </code></pre>
  
  <p>m_inbound_data is a char[3]</p>
  
  <p>Once cmd->parse() is done, it will call a callback <strong>command_is_done</strong></p>
  
  <pre><code>  void TCPConnection::command_is_done() {                                                                                                                                                                                                                   
      m_inbound_data[0] = '0';
      m_inbound_data[1] = '0';
      m_inbound_data[2] = '0';
  
      listenForCMD();
    }
  </code></pre>
  
  <p>The error occurs in the <strong>handle_cmd</strong> when checking for error at the first line.</p>
  
  <p>As I said before, the cmd->parse() will parse the command it just got, sometime lauching blocking code in a thread coming from a pool. On this thread it sends back data to the client with a synchronous write.</p>
  
  <p><strong>IMPORTANT THING :</strong> The callback <strong>command_is_done</strong> will always be called before the said thread is launched. this means that <strong>listenForCMD</strong> is already called when the thread may send something back to the client in synchronous write. Therefore my first worries.</p>