Skip to content

Commit deb8d43

Browse files
committed
avoid throwing exception from a critical section. Differ to when out
1 parent 60016db commit deb8d43

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Stream.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,30 @@ std::shared_ptr<Engine> Stream::open(const std::string& name, Mode mode)
122122
throw UnknownOpenModeException(XBT_THROW_POINT, mode_to_str(mode));
123123

124124
// Only the first Actor calling Stream::open has to create the corresponding Engine and Transport method.
125-
// Hence, we use a critical section.
125+
// Hence, we use a critical section. The creation of a FileEngine can raise an exception in the critical section
126+
// which requires special handling.
127+
bool got_exception = false;
128+
std::string exception_msg;
129+
126130
dtl_->lock();
127131
if (not engine_) {
128132
if (engine_type_ == Engine::Type::Staging) {
129133
engine_ = std::make_shared<StagingEngine>(name, this);
134+
engine_->create_transport(transport_method_);
130135
} else if (engine_type_ == Engine::Type::File) {
131-
engine_ = std::make_shared<FileEngine>(name, this);
136+
try {
137+
engine_ = std::make_shared<FileEngine>(name, this);
138+
engine_->create_transport(transport_method_);
139+
} catch(IncorrectPathDefinitionException e) {
140+
got_exception = true;
141+
exception_msg = std::string(e.what());
142+
}
132143
}
133-
engine_->create_transport(transport_method_);
134144
}
135145
dtl_->unlock();
146+
// Check if an exception has been raised and caugth while creating a FileEngine. If yes, throw it again.
147+
if (got_exception)
148+
throw IncorrectPathDefinitionException(XBT_THROW_POINT, exception_msg);
136149

137150
while (not engine_) {
138151
XBT_DEBUG("%s waits for the creation of the engine", sg4::this_actor::get_cname());

test/dtl_file_engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ TEST_F(DTLFileEngineTest, BogusStoragePaths)
9898
dtlmod::DTL::disconnect();
9999
});
100100
XBT_INFO("Simulation will fail as the Stream::open throws an exception from a critical section");
101-
ASSERT_DEATH(sg4::Engine::get_instance()->run(), ".*");
101+
sg4::Engine::get_instance()->run();
102102
});
103103
}
104104

0 commit comments

Comments
 (0)