FirebirdSQL / firebird

Firebird server, client and tools
https://firebirdsql.org
1.26k stars 217 forks source link

Assert in ~thread_db() due to not released page buffer #8283

Closed hvlad closed 1 month ago

hvlad commented 1 month ago

The issue happens when preparing a query that involves some table with expression index that depends on missing UDF.

In this case exception is thrown from MET_lookup_index_expression() and BTR_all() doesn't release IRT.

Call stack ``` engine13.dll!Firebird::status_exception::raise(status=0x000000000490e870) Line 138 engine13.dll!ERR_punt() Line 349 engine13.dll!par_error(blrReader={...}, v={...}, isSyntaxError=true) Line 765 engine13.dll!PAR_error(csb=0x000000000d7af8d0, v={...}, isSyntaxError=true) Line 771 engine13.dll!Jrd::UdfCallNode::parse(tdbb=0x000000000490e540, pool={...}, csb=0x000000000d7af8d0, blrOp='d') Line 12908 engine13.dll!PAR_parse_node(tdbb=0x000000000490e540, csb=0x000000000d7af8d0) Line 1650 engine13.dll!PAR_blr(tdbb=0x000000000490e540, relation=0x00000000083453d0, blr=0x0000000004909c38, blr_length=22, view_csb=0x0000000000000000, csb_ptr=0x000000000490a048, statementPtr=0x0000000000000000, trigger=false, flags=0) Line 187 engine13.dll!MET_parse_blob(tdbb=0x000000000490e540, relation=0x00000000083453d0, blob_id=0x0000000004909ee8, csb_ptr=0x000000000490a048, statementPtr=0x0000000000000000, trigger=false, validationExpr=false) Line 8277 engine13.dll!MET_lookup_index_expression(tdbb=0x000000000490e540, relation=0x00000000083453d0, idx=0x000000000490a530) Line 7599 engine13.dll!BTR_description(tdbb=0x000000000490e540, relation=0x00000000083453d0, root=0x000000000bf60000, idx=0x000000000490a530, id=9) Line 999 engine13.dll!BTR_all(tdbb=0x000000000490e540, relation=0x00000000083453d0, idxList={...}, relPages=0x00000000083455a0) Line 832 engine13.dll!Jrd::Optimizer::compileRelation(stream=0) Line 1189 ```

In DEBUG build it triggers assert later

Call stack ``` engine13.dll!fb_assert_impl(msg=0x00007ffc7c407ed8, file=0x00007ffc7c3fafe8, line=547, do_abort=true) Line 47 C++ engine13.dll!Jrd::thread_db::~thread_db() Line 547 C++ engine13.dll!Jrd::ThreadContextHolder::~ThreadContextHolder() Line 801 C++ [External Code] engine13.dll!Jrd::JAttachment::prepare(user_status=0x000000000490e868, apiTra=0x0000000002ec4658, stmtLength=65, sqlStmt=0x00000000001c4de0, dialect=3, flags=71) Line 5667 C++ ```

In RELEASE build engine might hang on detach or earlier.