I believe I have figured out what is happening here: There are several threads 
in the thread pool. Thread A is started and opens a database connection and all 
is fine so far. Then thread B is started and doesn't get a database connection 
any more, it throws an exception. The exception is propagated and as part of 
that propagation lots of things are destructed. At some point the data 
structure containing the information about tables is destructed. Now thread A 
gets a chance to run again and wants to build the `CREATE INDEX` command. It 
needs the information about the tables, but that was destructed already. And 
then it segfaults.

To solve this we would need to make sure all threads are destructed *before* 
anything else. But there is no way to kill a running std::thread. We would have 
to wait until it is done with its work, which doesn't make much sense, because 
that situation isn't recoverable anyway. In C++20 there is a new `std::jthread` 
which has some mechanism for stopping it from the outside, but I believe that 
also only works if the thread cooperates. But if that thread just called 
`CREATE INDEX` it might be a long time before it even gets to run and can 
notice that it should shutdown.

At the moment, I don't have a good idea how to solve this. :-(

-- 
Reply to this email directly or view it on GitHub:
https://github.com/osm2pgsql-dev/osm2pgsql/issues/2265#issuecomment-2539463603
You are receiving this because you are subscribed to this thread.

Message ID: <osm2pgsql-dev/osm2pgsql/issues/2265/[email protected]>
_______________________________________________
Tile-serving mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/tile-serving

Reply via email to