Catch-anything and pthread_cancel

23 views
Skip to first unread message

Dimitry Sibiryakov

unread,
Apr 11, 2026, 6:02:42 PM (13 days ago) Apr 11
to firebir...@googlegroups.com
Hello All,

I think that there is another problem in Firebird exception handling code:
catch-anything (catch(...)) blocks are used that swallow whatever they got.
Unfortunately pthread_cancel() call uses abi::__forced_unwind exception
internally and when this exception is swallowed the thread cancellation silently
fail.

--
WBR, SD.

Alex Peshkoff

unread,
Apr 13, 2026, 2:38:52 AM (11 days ago) Apr 13
to firebir...@googlegroups.com
I see the only suspicious place with such code - DsqlRequest::destroy(). Must say I see absolutely no sense using subj in this function. 

Another place where ... is not rethrown is PluginManager::registerPluginFactory() which is called from FB_PLUGIN_ENTRY_POINT and here such catch probably makes sense to avoid crossing module boundary.

In ListEntry::scan() exception is rethrown.


May be simply fix one place?


Dimitry Sibiryakov

unread,
Apr 13, 2026, 3:49:09 AM (11 days ago) Apr 13
to firebir...@googlegroups.com
Alex Peshkoff wrote 13.04.2026 8:38:
> I see the only suspicious place with such code - DsqlRequest::destroy(). Must
> say I see absolutely no sense using subj in this function.

May be you miss bigger picture: fbclient and engine are libraries that in
embedded mode are called directly from user application. And if this application
call pthread_cancel() any time when the thread execution point is inside of
CLOOP envelopes, it will receive "Unrecognized C++ exception" from API call
instead of thread cancellation.

--
WBR, SD.

Dimitry Sibiryakov

unread,
Apr 13, 2026, 4:12:07 AM (11 days ago) Apr 13
to firebir...@googlegroups.com
Alex Peshkoff wrote 13.04.2026 8:38:
> Another place where ... is not rethrown is
> PluginManager::registerPluginFactory() which is called from
> FB_PLUGIN_ENTRY_POINT and here such catch probably makes sense to avoid crossing
> module boundary.

This is Linux-specific exception and it is supposed to safely cross library
boundaries being thrown from GLIBC and caught in GLIBC as well. This is a safe
case because intermediate stack frames from other libraries are unwinded in bunch.

> May be simply fix one place?

I think every such place can be fixed by adding

#ifdef PTHREAL_CANCEL
catch (abi::__forced_unwind)
{
<whatever (...) below does useful>
throw;
}
#endif

Except Interface.h where autoconf-generated macros cannot be used.

--
WBR, SD.

Alex Peshkoff

unread,
Apr 13, 2026, 12:26:03 PM (11 days ago) Apr 13
to firebir...@googlegroups.com
pybind11 is using:

#ifdef __GLIBCXX__
        catch (abi::__forced_unwind &) {
            throw;
        }
#endif


Reply all
Reply to author
Forward
0 new messages