Skip to content

Commit 687ea4c

Browse files
committed
Fix: Results of tasks run in thread pool were not checked
If a function run in the thread pool throws an exception, this exception was never "collected", it was silently ignored. This commit fixes this by wrapping the osmium::thread::Pool class in a class of our own that keeps track of the futures returned by submit() and allows checking them.
1 parent 131dac7 commit 687ea4c

18 files changed

+73
-24
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(osm2pgsql_lib_SOURCES
6666
taginfo-impl.hpp
6767
taginfo.hpp
6868
tagtransform.hpp
69+
thread-pool.hpp
6970
util.hpp
7071
wildcmp.hpp
7172
wkb.hpp

src/middle-pgsql.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void middle_pgsql_t::commit()
586586

587587
void middle_pgsql_t::flush() { m_db_copy.sync(); }
588588

589-
void middle_pgsql_t::stop(osmium::thread::Pool &pool)
589+
void middle_pgsql_t::stop(thread_pool_t &pool)
590590
{
591591
m_cache.reset();
592592
if (m_out_options->flat_node_cache_enabled) {

src/middle-pgsql.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct middle_pgsql_t : public slim_middle_t
5858
middle_pgsql_t(options_t const *options);
5959

6060
void start() override;
61-
void stop(osmium::thread::Pool &pool) override;
61+
void stop(thread_pool_t &pool) override;
6262
void analyze() override;
6363
void commit() override;
6464

src/middle-ram.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool middle_ram_t::relation_get(osmid_t id,
110110
return true;
111111
}
112112

113-
void middle_ram_t::stop(osmium::thread::Pool &)
113+
void middle_ram_t::stop(thread_pool_t &)
114114
{
115115
m_cache.reset();
116116
m_ways.clear();

src/middle-ram.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct middle_ram_t : public middle_t, public middle_query_t
9595
virtual ~middle_ram_t() noexcept = default;
9696

9797
void start() override {}
98-
void stop(osmium::thread::Pool &pool) override;
98+
void stop(thread_pool_t &pool) override;
9999
void analyze() override {}
100100
void commit() override {}
101101

src/middle.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
#include <cstddef>
1313
#include <memory>
1414

15-
#include <osmium/thread/pool.hpp>
16-
1715
#include "osmtypes.hpp"
1816
#include "reprojection.hpp"
17+
#include "thread-pool.hpp"
1918

2019
/**
2120
* Interface for returning information about raw OSM input data from a cache.
@@ -88,7 +87,7 @@ struct middle_t
8887
virtual ~middle_t() = 0;
8988

9089
virtual void start() = 0;
91-
virtual void stop(osmium::thread::Pool &pool) = 0;
90+
virtual void stop(thread_pool_t &pool) = 0;
9291
virtual void analyze(void) = 0;
9392
virtual void commit(void) = 0;
9493

src/osmdata.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <vector>
1010

1111
#include <osmium/io/any_input.hpp>
12-
#include <osmium/thread/pool.hpp>
1312
#include <osmium/visitor.hpp>
1413

1514
#include "db-copy.hpp"
@@ -19,6 +18,7 @@
1918
#include "options.hpp"
2019
#include "osmdata.hpp"
2120
#include "output.hpp"
21+
#include "thread-pool.hpp"
2222
#include "util.hpp"
2323

2424
osmdata_t::osmdata_t(std::unique_ptr<dependency_manager_t> dependency_manager,
@@ -395,7 +395,7 @@ void osmdata_t::process_stage3() const
395395
{
396396
// All the intensive parts of this are long-running PostgreSQL commands.
397397
// They will be run in a thread pool.
398-
osmium::thread::Pool pool{m_parallel_indexing ? m_num_procs : 1, 512};
398+
thread_pool_t pool{m_parallel_indexing ? m_num_procs : 1};
399399

400400
if (m_droptemp) {
401401
// When dropping middle tables, make sure they are gone before
@@ -415,9 +415,9 @@ void osmdata_t::process_stage3() const
415415
m_mid->stop(pool);
416416
}
417417

418-
// Waiting here for pool to execute all tasks.
419-
// XXX If one of them has an error, all other will finish first,
420-
// which may take a long time.
418+
// Waiting here for pool to execute all tasks. If one of them throws an
419+
// exception, this will throw.
420+
pool.check_for_exceptions();
421421
}
422422

423423
void osmdata_t::stop() const

src/output-flex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ void output_flex_t::sync()
10921092
}
10931093
}
10941094

1095-
void output_flex_t::stop(osmium::thread::Pool *pool)
1095+
void output_flex_t::stop(thread_pool_t *pool)
10961096
{
10971097
for (auto &table : m_table_connections) {
10981098
pool->submit([&]() {

src/output-flex.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class output_flex_t : public output_t
112112
std::shared_ptr<db_copy_thread_t> const &copy_thread) const override;
113113

114114
void start() override;
115-
void stop(osmium::thread::Pool *pool) override;
115+
void stop(thread_pool_t *pool) override;
116116
void sync() override;
117117

118118
void stage2_proc() override;

src/output-gazetteer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class output_gazetteer_t : public output_t
4242
}
4343

4444
void start() override;
45-
void stop(osmium::thread::Pool *) noexcept override {}
45+
void stop(thread_pool_t *) noexcept override {}
4646
void sync() override;
4747

4848
bool need_forward_dependencies() const noexcept override { return false; }

0 commit comments

Comments
 (0)