Open yangguang0756 opened 3 years ago
Can you provide more details - content of the error log? What are you doing.
This exception is thrown when you try to use application().context() or any stuff that requies it (like sessions request/reponse) outside the scope of actual request - i.e. when there is no active request for the application.
Do you have stack trace? (usually it prints it if you use MSVC + Debug Info)
code: EchoController::EchoController(::cppcms::service &srv) : cppcms::application(srv) { dispatcher().assign("", &EchoController::echo, this); mapper().assign(""); // default URL }
void EchoController::echo() { BOOSTER_DEBUG("EchoController") << "echo [" << ::GetCurrentThreadId() << "]";
if (request().request_method() == "POST") <==this line throw exception { ... } }
===========
log:
2020-12-17 18:52:13; EchoController, debug: echo [2672] (echocontroller.cpp:87)
2020-12-17 18:52:13; cppcms, error: Caught exception [Access to unassigned context]
00007FFD950CC6B5: booster::stack_trace::trace +0x45
00007FFD955921F9: booster::backtrace::backtrace +0x99
00007FFD955947B2: booster::runtime_error::runtime_error +0x52
00007FFD955940E2: cppcms::cppcms_error::cppcms_error +0x32
00007FFD95621EAE: cppcms::application::context +0xce
00007FFD95621F38: cppcms::application::request +0x28
00007FF700C8CE0A: App::Http::Controllers::EchoController::echo +0x16a
00007FF700C7FCCC: cppcms::url_dispatcher::binder0anonymous namespace'::base_handler<std::function<void __cdecl(void)> >::execute_handler +0x2d 00007FFD95631E90: cppcms::
anonymous namespace'::base_handler<std::function<void cdecl(void)> >::dispatch +0x60
00007FFD956274E3: cppcms::url_dispatcher::dispatch +0x193
00007FFD95622E69: cppcms::application::main +0x99
00007FFD9563201B: cppcms::anonymous namespace'::mounted::dispatch +0xbb 00007FFD956274E3: cppcms::url_dispatcher::dispatch +0x193 00007FFD95622E69: cppcms::application::main +0x99 00007FFD95606591: cppcms::http::context::dispatch +0x2c1 00007FFD95606296: cppcms::http::context::dispatch +0x276 00007FFD9560BEF3: cppcms::http::
anonymous namespace'::dispatcher::operator() +0x53
00007FFD956086C0: std::_Invoker_functor::_Call<cppcms::http::anonymous namespace'::dispatcher & __ptr64> +0x30 00007FFD95609F50: std::invoke<cppcms::http::
anonymous namespace'::dispatcher & ptr64> +0x30
00007FFD956089D4: std::_Invoke_ret<void,cppcms::http::`anonymous namespace'::dispatcher & ptr64> +0x34
00007FFD9560C8F5: std::_Func_impl<cppcms::http::`anonymous namespace'::dispatcher,std::allocator
ENV: win10/nginx-1.15.9/fastcgi/cppcms-2.0.0.beta2|1.2.1
only sometimes occur.
How to solve this problem? I need help, thanks.