4

I have strange behaviour in server program. In simple example it works fine (I insert traces everywhere, in pion and asio).

#include <pion/http/server.hpp>
#include <pion/http/response_writer.hpp>
#include <pion/http/response_reader.hpp>
#include <pion/http/request_writer.hpp>
#include <pion/logger.hpp>
#include <pion/scheduler.hpp>

int main()
{
   pion::single_service_scheduler shed;
   shed.set_num_threads(1);
   boost::shared_ptr<pion::http::server> server
   (new pion::http::server(shed, 5000));
   server->add_resource("/", handlerFunction);
   server->start();
   sleep(5);
}

output is like this. Construct socket for acceptor, construct socket for client, tcp connection is created, all works fine.

basic io object constructor
after service construct
basic io object constructor
after service construct
basic io object constructor
Address of socket is: 0x9855fa4 value: -1
after service construct
1422519945 INFO pion.http.server Added request handler for HTTP resource: 
1422519945 INFO pion.http.server Starting server on port 5000
before connection create
before connection constructor called
basic io object constructor
basic_stream_socket::construct
Address of socket is: 0x9857514 value: -1
after impl.construct
after service construct
basic io object constructor
after service construct
basic io object constructor
after service construct
ssl socket constructed
connection constructor, is_ssl: 0
after connection create: 0x98574f8
before accept
after accept

In more complicated program with same code, but with oracle and many other libraries output is like this.

basic io object constructor
after service construct
basic io object constructor
after service construct
basic io object constructor
Address of socket is: 0xbfe47a64 value: -1
after service construct
1422525476 INFO pion.http.server Added request handler for HTTP resource: 
before connection create
basic io object constructor
after service construct
basic io object constructor
after service construct
after connection create: 0x8fe8b88
before accept
in connection::async_accept
after accept

No second socket created, actually, there is no call of connection::create, but connection has address as you can see. I have idea, that somewhere something writes on address of function connection::create (or something like). Can you please help, how can I catch this?

ForEveR
  • 55,233
  • 2
  • 119
  • 133
  • 3
    Assuming `clang` or `gcc` they have sanitizers, [here](http://stackoverflow.com/q/22699881/1708801) and [here](http://stackoverflow.com/q/20738232/1708801) – Shafik Yaghmour Jan 29 '15 at 10:27
  • @ShafikYaghmour thanks, but there is no gcc 4.9 for ubuntu yet (in stable repo, also this will take a while for rebuild all libs for gcc 4.9), clang sanitizer should be used with -stdlib=libc++ as I can see, but pion use internally tr1/unordered_map. – ForEveR Jan 29 '15 at 10:57
  • Was just problems with build, some libraries with C++11, some without... Without C++11 all works fine... – ForEveR Jan 30 '15 at 09:06
  • Oh interesting, [this question](http://stackoverflow.com/q/28201173/1708801) is related. – Shafik Yaghmour Jan 30 '15 at 10:19

1 Answers1

2

On ubuntu, I like to run with valgrind (http://valgrind.org/).

sudo apt-get install valgrind
valgrind ./mypgrogram

It doesn't report all issues, but when it does, it will report the nature and origin.

Also recommended:

valgrind --db-attach=yes ./myprogram

Which allows you to debug (backtrace, inspect) and continue the program when a violation/uninitialized memory reference is detected.

On some older Ubunti I had to use sudo to make valgrind be able to attach gdb:

sudo -E valgrind --db-attach=yes ./myprogram

If tr1/unordered_map should be quite trivial to replace with std::unordered_map

E.g. with a quick hack

#include <unordered_map>

namespace std { namespace tr1 {

    using std::unordered_map;
    using std::hash;
    // etc...
} }
    

Of course this is not good practice, and you might just want to typedef between std::unordered_map and std::tr1::unordered_map instead, but in the interest of quick checks...

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks, tried with valgrind, but there is many-many memory errors from oracle and nothing else. Will try with --db-attach... – ForEveR Jan 29 '15 at 12:29
  • There might be suppression rules for the oracle libraries you mention. Also, you might be able to cut oracle out of the loop (divide-and-conquer). – sehe Jan 29 '15 at 12:30
  • Actually, now I can't reproduce this situation on my machine, remove all traces, etc, but no... Probably moon phase has been replaced... – ForEveR Jan 29 '15 at 12:35
  • Or a full rebuild occurred :) – sehe Jan 29 '15 at 12:36
  • reproduced... But valgrind, either with db-attach says only about uninitialized variable in implementation, no idea about `connection::create`... It just not called. – ForEveR Jan 29 '15 at 14:14
  • @ForEveR Only one way, IMHO: keep reducing (either by eliminating more and more, or by starting with a fresh project and adding things until it breaks). Pay special attention to shared library compatibilities etc. – sehe Jan 29 '15 at 14:22
  • Hard way, but may be I will try to do this. Thanks. – ForEveR Jan 29 '15 at 14:40