[Cppcms-users] cppdb::session connection pool makes asynchronous apps unstable
Brought to you by:
artyom-beilis
|
From: CN <cn...@fa...> - 2013-12-10 07:02:15
|
This program mounts both synchronous and asynchronous applications. Both
applications use cppdb::session. If the asynchronous application's
constructor includes connection pool (@pool_size=10) in cppdb::session
constructor's parameter, this program silently terminates immediately
after browser sends requests.
The deepest spot of the source I can trace trying to locate the problem
is exec() at line 465 in ~/booster/lib/aio/src/io_service.cpp:
try {
exec();
}
catch(...) {
data_mutex_.lock();
throw;
}
I guess exec() must have thrown an uncaught exception and leads to
program termination.
What I have no clue is why singleton cppdb::session can make the system
unstable. If "@pool_size=10" is not included in cppdb::session's
constructor parameter, then the program seems to run properly.
This weird behavior happens only to asynchronous applications.
Any enlightenment will be much appreciated!
---This file should be able to compile and run:---
#include <cppcms/service.h>
#include <cppcms/rpc_json.h>
#include <cppdb/frontend.h>
#include <cppcms/applications_pool.h>
#include <cppcms/mount_point.h>
#include <cppcms/url_dispatcher.h>
#include <cppcms/url_mapper.h>
#include <cppcms/http_context.h>
#include <cppcms/session_interface.h>
#include <cppcms/service.h>
#include <cppcms/http_request.h>
#include <cppcms/http_response.h>
#include <fstream>
class sync : public cppcms::application
{
public:
sync(cppcms::service &s) : cppcms::application(s){
cppdb::session
sess("postgresql:@pool_size=10;dbname=mydb;user=myname;password=mypassword");
sess << "SET TIME ZONE 'UTC'" << cppdb::exec;
dispatcher().assign(".*",&sync::show,this);
}
private:
void show(){
std::ifstream myfile("/tmp/t.html");
if(myfile.is_open()){
std::string line;
while(std::getline(myfile,line))
response().out() << line;
myfile.close();
}
}
};
class as : public cppcms::rpc::json_rpc_server
{
public:
as(cppcms::service &s) : cppcms::rpc::json_rpc_server(s){
//Next statement causes the program to terminate
silently immediately after reqested:
cppdb::session
sess("postgresql:@pool_size=10;dbname=mydb;user=myname;password=mypassword");
//Next statement does not cause problem:
//cppdb::session
sess("postgresql:dbname=mydb;user=myname;password=mypassword");
}
};
int main(int argc,char ** argv)
{
cppcms::service s(argc,argv);
s.applications_pool().mount(cppcms::applications_factory<sync>(),cppcms::mount_point("^/(?!as)(.*)",1));
s.applications_pool().mount(new
as(s),cppcms::mount_point("^/as/(.+)",1));
s.run();
return 0;
}
---file "/tmp/t.html":---
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript" src="jsonrpc.js"></script>
<script type="text/javascript">
rpc=new JsonRPC('/as',['any'],[]);
rpc.any.on_result=function(r){ alert('ok'); }
rpc.any.on_error=function(e){ alert('oops'); }
</script>
</head>
<body>
my test.
</body>
</html>
---end of files---
Regards,
CN
--
http://www.fastmail.fm - The professional email service
|