Reputation: 2184
I've made a simple TCP Server using Boost Asio (1.53.0). The Server accepts JSON-Requests, parse them with boost::property_tree::read_json.
To test the reliability, I created a simple Application which creates 128 Threads and they send continually Requests.
After a few seconds, the server crashes with an Access Violation:
Unhandled exception at 0x000007FEFD829E5D (KernelBase.dll) in RPC_Server.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.
msvcr110d.dll!__RethrowException(EHExceptionRecord * pThisException) Line 1217
msvcr110d.dll!__CxxCallCatchBlock(_EXCEPTION_RECORD * pExcept) Line 1279
ntdll.dll!0000000077360c21()
RPC_Server.exe!json::json::Parse(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & sJson) Line 28
Here get's read_json called:
rpc::request json::Parse(std::string sJson)
{
try {
std::stringstream ss;
ss << sJson;
boost::property_tree::ptree pt;
boost::property_tree::read_json(ss, pt);
...
}
Upvotes: 2
Views: 1198
Reputation: 2184
Seems like boost::property_tree::read_json isn't thread-safe by default.
You have to define:
#define BOOST_SPIRIT_THREADSAFE
Upvotes: 2