Thrift TThreadPoolServer returns "Segmentation fault; core dumped;" when handle concurrent MySQL database requests -


i'm developing simple assignment using apache thrift , c++ poco library. assignment requires me make benchmark creating multiple concurrent threads make same request thrift tthreadpoolserver.

this client-side code, creates 10 concurrent threads, of them make same get request (request info 1 user d) server:

// define myworker class inherits runnable class myworker : public runnable {     public:      myworker(int k = -1) : runnable(), n(k) {     }      void run() {         // create connection         boost::shared_ptr<ttransport> socket(new tsocket("localhost", 9090));         boost::shared_ptr<ttransport> transport(new tbufferedtransport(socket));         boost::shared_ptr<tprotocol> protocol(new tbinaryprotocol(transport));         apisclient client(protocol);         try {             transport->open();             int res = -1;             // make request             res = client.get("d");              printf("thread %d, res = %d \n", n, res);             transport->close();         } catch (texception te) {             cout << te.what() << endl;         }     } private:     int n; };  void handlebenchmarktest(const std::string& name, const std::string& value) {         //todo!         const int n = 10;         myworker w[n];         (int = 0; < n; i++) w[i] = myworker(i);         thread t[n];         (int = 0; < n; i++) t[i].start(w[i]);         (int = 0; < n; i++) t[i].join(); // wait threads end          cout << endl << "threads joined" << endl;     } 

i implemented server using tthreadpoolserver. the handler function when server receive get request:

   // function make use of poco::data    int getrequest(const std::string& _username) {             int res = -1;             statement select(*mysqlsession);             std::string match("'" + _username + "'");             select << "select counter view_count_info username = " + match + " limit 1;", into(res);             select.execute();             return res;         } 

above of codes. when run client-side benchmark app, returned:

mysql // try-catch block above mysql // try-catch block above thread 2, res = -1 // expected result mysql // try-catch block above thrift: fri jun 26 15:54:05 2015 tsocket::read() recv() <host: localhost port: 9090>connection reset peer no more data read. thrift_econnreset no more data read. no more data read. thrift: fri jun 26 15:54:05 2015 tsocket::read() recv() <host: localhost port: 9090>connection reset peer thrift_econnreset thrift: fri jun 26 15:54:05 2015 tsocket::read() recv() <host: localhost port: 9090>connection reset peer thrift_econnreset  threads joined 

in server, result is:

2015-06-26 08:54:00 : > server running 2015-06-26 08:54:05 : handle request d 2015-06-26 08:54:05 : handle request d 2015-06-26 08:54:05 : handle request d -1 2015-06-26 08:54:05 : handle request 2015-06-26 08:54:05 : handle request d 2015-06-26 08:54:05 : handle request d 2015-06-26 08:54:05 : handle request d d  run finished; segmentation fault; core dumped; real time: 5s; user: 0ms; system: 0ms 

i don't know why happened. one more thing, when try change not use mysql request in server side (instead return random integer each request), app runs without errors or warning. guess problem here mysql database. work if make 1 request @ time, goes wrong when there multiple, concurrent get requests made.

thanks @jensg, found out problem here because used global variable mysqlsession handle mysql database requests, causes threads conflict. again !


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -