Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3c4e551
engine: return new handles from `EngineHandle::initEngine`
jpsim Mar 25, 2022
1510d2e
Fix C++ stream
jpsim Mar 28, 2022
1575c81
Fix engine handles in JNI interfaces
jpsim Mar 28, 2022
4c3d502
Send engine handles in `main_interface_test.cc`
jpsim Mar 28, 2022
1a60392
Fix common tests build failures
jpsim Mar 28, 2022
adb4e8d
Fix termination issues
jpsim Mar 28, 2022
2ff0da3
Fix `engine_test.cc`
jpsim Mar 28, 2022
3ab61c7
Fix `main_interface_test.cc`
jpsim Mar 28, 2022
2978642
Fix typo in comment
jpsim Mar 28, 2022
14180f8
Rename the overload of sendData that takes a byte array
jpsim Mar 28, 2022
41f65ba
WIP: Disable test to see what other failures there are
jpsim Mar 28, 2022
2dabcc3
fixup! WIP: Disable test to see what other failures there are
jpsim Mar 28, 2022
b5f2b0a
WIP: Disable failing cronet tests temporarily
jpsim Mar 28, 2022
1f35665
Release engine in C++ tests to avoid asan detecting the leaks
jpsim Mar 29, 2022
9954283
fixup! Release engine in C++ tests to avoid asan detecting the leaks
jpsim Mar 29, 2022
b38e283
Remove outdated comment
jpsim Mar 29, 2022
6e6b81b
Re-add disabled parts of `EngineApiTest.kt`
jpsim Mar 29, 2022
bf08759
Merge branch 'main' into jp-real-engine-handles
jpsim Mar 29, 2022
8b2ec75
Re-add cronet_url_request_context_test
jpsim Mar 29, 2022
1122144
Re-add `urlconnection_test`
jpsim Mar 29, 2022
43ae8ca
Revert "Re-add disabled parts of `EngineApiTest.kt`"
jpsim Mar 29, 2022
819b2cb
Fix `CompareDefaultWithCronet` tests
jpsim Mar 29, 2022
c907a2f
Update ignore messages
jpsim Mar 30, 2022
dcc64dd
Add tmate step to debug failing test
jpsim Mar 30, 2022
d2b9b26
fixup! Add tmate step to debug failing test
jpsim Mar 30, 2022
39fcee7
fixup! fixup! Add tmate step to debug failing test
jpsim Mar 30, 2022
85d5d3a
Revert "Revert "Re-add disabled parts of `EngineApiTest.kt`""
jpsim Mar 30, 2022
25e3ffe
Revert "Add tmate step to debug failing test"
jpsim Mar 30, 2022
1fb3d96
Add FIXME to unblock moving forward
jpsim Mar 30, 2022
d505306
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Mar 31, 2022
a817d3e
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Apr 5, 2022
3e8b2c1
Remove dispatch_once calls from EnvoyNetworkMonitor
jpsim Apr 5, 2022
6affb63
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Apr 12, 2022
9cc9f56
Move termination checking to the dispatcher
jpsim Apr 12, 2022
78a1d9e
Pull in changes from https://github.com/envoyproxy/envoy-mobile/pull/…
jpsim Apr 12, 2022
7adabb7
fixup! Pull in changes from https://github.com/envoyproxy/envoy-mobil…
jpsim Apr 12, 2022
1d73144
Revert comment word change
jpsim Apr 12, 2022
6b22353
Add missing parameter documentation
jpsim Apr 12, 2022
bda80bd
Remove `getHandle()` APIs
jpsim Apr 12, 2022
25071ae
Remove NOLINT comments
jpsim Apr 12, 2022
c17da3c
Merge branch 'main' into jp-real-engine-handles
jpsim Apr 13, 2022
a768801
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim May 17, 2022
24cb769
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim May 26, 2022
c5e9936
Disable global stats
jpsim May 26, 2022
453d7ab
Add inline yaml comment
jpsim May 26, 2022
d67ec50
engine: remove log delegate pointer explicit reset
jpsim May 26, 2022
2a00d25
Re-enable ignored cronet tests
jpsim May 26, 2022
32fcf13
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Jun 14, 2022
8b9cf77
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Jun 15, 2022
c6e3654
Remove outdated test that no longer applies
jpsim Jun 15, 2022
546633e
api: return opaque engine handle in `onEngineRunning`
jpsim Jun 14, 2022
03fde4d
fixup! api: return opaque engine handle in `onEngineRunning`
jpsim Jun 15, 2022
b7435d0
Revert "api: return opaque engine handle in `onEngineRunning`"
jpsim Jun 16, 2022
d6152c8
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Jun 16, 2022
31a27fe
Expose default handle API
jpsim Jun 16, 2022
4add65d
Merge remote-tracking branch 'main' into jp-real-engine-handles
jpsim Jun 28, 2022
586bdad
Merge remote-tracking branch 'origin/main' into jp-real-engine-handles
jpsim Jul 5, 2022
20b30b8
Add release notes entry
jpsim Jul 5, 2022
15b631c
Revert "Expose default handle API"
jpsim Jul 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Breaking changes:
- iOS: enable usage of ``NWPathMonitor`` by default (:issue:`#2329 <2329>`)
- iOS: replace ``enableNetworkPathMonitor`` with a new ``setNetworkMonitoringMode`` API to allow disabling monitoring (:issue:`#2345 <2345>`)
- iOS: release artifacts no longer embed bitcode
- api: engines are no longer a singleton, you may need to update your code to only create engines once and hold on to them.
You also cannot assume that an `envoy_engine_t` value of `1` will return the default engine.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Not sure this strictly needs to be in release notes, since technically this is not a public type/interface.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although it's possible to have relied on the fact that this was a predictable value from external consumers, as brittle as that may have been.

Support for using multiple engines concurrently is coming later. (:issue:`#2129 <2129>`)

Bugfixes:

Expand Down
2 changes: 1 addition & 1 deletion library/cc/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void Engine::terminate() {
if (terminated_) {
throw std::runtime_error("attempting to double terminate Engine");
}
terminate_engine(engine_);
terminate_engine(engine_, /* release */ false);
terminated_ = true;
}

Expand Down
2 changes: 1 addition & 1 deletion library/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve
});
}

// We let the thread clean up this log delegate pointer
if (logger_.log) {
log_delegate_ptr_ =
std::make_unique<Logger::LambdaDelegate>(logger_, Logger::Registry::getSink());
Expand Down Expand Up @@ -143,7 +144,6 @@ envoy_status_t Engine::main(const std::string config, const std::string log_leve
connectivity_manager_.reset();
client_scope_.reset();
stat_name_set_.reset();
log_delegate_ptr_.reset(nullptr);
main_common.reset(nullptr);
bug_handler_registration_.reset(nullptr);
assert_handler_registration_.reset(nullptr);
Expand Down
43 changes: 16 additions & 27 deletions library/common/engine_handle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,36 @@

namespace Envoy {

envoy_status_t EngineHandle::runOnEngineDispatcher(envoy_engine_t,
envoy_status_t EngineHandle::runOnEngineDispatcher(envoy_engine_t handle,
std::function<void(Envoy::Engine&)> func) {
if (auto e = engine()) {
return e->dispatcher().post([func]() {
if (auto e = engine()) {
func(*e);
}
});
if (auto engine = reinterpret_cast<Envoy::Engine*>(handle)) {
return engine->dispatcher().post([engine, func]() { func(*engine); });
}
return ENVOY_FAILURE;
}

envoy_engine_t EngineHandle::initEngine(envoy_engine_callbacks callbacks, envoy_logger logger,
envoy_event_tracker event_tracker) {
// TODO(goaway): return new handle once multiple engine support is in place.
// https://github.com/envoyproxy/envoy-mobile/issues/332
strong_engine_ = std::make_shared<Envoy::Engine>(callbacks, logger, event_tracker);
engine_ = strong_engine_;
return 1;
auto engine = new Envoy::Engine(callbacks, logger, event_tracker);
return reinterpret_cast<envoy_engine_t>(engine);
}

envoy_status_t EngineHandle::runEngine(envoy_engine_t, const char* config, const char* log_level,
const char* admin_address_path) {
// This will change once multiple engine support is in place.
// https://github.com/envoyproxy/envoy-mobile/issues/332
if (auto e = engine()) {
e->run(config, log_level, admin_address_path);
envoy_status_t EngineHandle::runEngine(envoy_engine_t handle, const char* config,
const char* log_level, const char* admin_address_path) {
if (auto engine = reinterpret_cast<Envoy::Engine*>(handle)) {
engine->run(config, log_level, admin_address_path);
return ENVOY_SUCCESS;
}

return ENVOY_FAILURE;
}

void EngineHandle::terminateEngine(envoy_engine_t) {
// Reset the primary handle to the engine, but retain it long enough to synchronously terminate.
auto e = strong_engine_;
strong_engine_.reset();
e->terminate();
void EngineHandle::terminateEngine(envoy_engine_t handle, bool release) {
auto engine = reinterpret_cast<Envoy::Engine*>(handle);
engine->terminate();
if (release) {
// TODO(jpsim): Always delete engine to avoid leaking it
delete engine;
}
}

EngineSharedPtr EngineHandle::strong_engine_;
EngineWeakPtr EngineHandle::engine_;

} // namespace Envoy
12 changes: 2 additions & 10 deletions library/common/engine_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,18 @@ class EngineHandle {
std::function<void(Envoy::Engine&)> func);

private:
static std::shared_ptr<Envoy::Engine> engine() {
// TODO(goaway): enable configurable heap-based allocation
return engine_.lock();
}

static envoy_engine_t initEngine(envoy_engine_callbacks callbacks, envoy_logger logger,
envoy_event_tracker event_tracker);
static envoy_status_t runEngine(envoy_engine_t, const char* config, const char* log_level,
const char* admin_address_path);
static void terminateEngine(envoy_engine_t);

static EngineSharedPtr strong_engine_;
static EngineWeakPtr engine_;
static void terminateEngine(envoy_engine_t handle, bool release);

// Allow a specific list of functions to access the internal setup/teardown functionality.
friend envoy_engine_t(::init_engine)(envoy_engine_callbacks callbacks, envoy_logger logger,
envoy_event_tracker event_tracker);
friend envoy_status_t(::run_engine)(envoy_engine_t, const char* config, const char* log_level,
const char* admin_address_path);
friend void ::terminate_engine(envoy_engine_t engine);
friend void ::terminate_engine(envoy_engine_t engine, bool release);
};

} // namespace Envoy
2 changes: 1 addition & 1 deletion library/common/jni/jni_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ extern "C" JNIEXPORT jint JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibra

extern "C" JNIEXPORT void JNICALL Java_io_envoyproxy_envoymobile_engine_JniLibrary_terminateEngine(
JNIEnv* env, jclass, jlong engine_handle) {
terminate_engine(static_cast<envoy_engine_t>(engine_handle));
terminate_engine(static_cast<envoy_engine_t>(engine_handle), /* release */ false);
}

extern "C" JNIEXPORT jstring JNICALL
Expand Down
4 changes: 3 additions & 1 deletion library/common/main_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ envoy_status_t run_engine(envoy_engine_t engine, const char* config, const char*
return Envoy::EngineHandle::runEngine(engine, config, log_level, admin_path);
}

void terminate_engine(envoy_engine_t engine) { Envoy::EngineHandle::terminateEngine(engine); }
void terminate_engine(envoy_engine_t engine, bool release) {
Envoy::EngineHandle::terminateEngine(engine, release);
}

envoy_status_t reset_connectivity_state(envoy_engine_t e) {
return Envoy::EngineHandle::runOnEngineDispatcher(
Expand Down
3 changes: 2 additions & 1 deletion library/common/main_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ envoy_status_t run_engine(envoy_engine_t engine, const char* config, const char*
* Terminate an engine. Further interactions with a terminated engine, or streams created by a
* terminated engine is illegal.
* @param engine, handle to the engine to terminate.
* @param release, set to true to release the engine from memory.
*/
void terminate_engine(envoy_engine_t engine);
void terminate_engine(envoy_engine_t engine, bool release);

/**
* Refresh DNS, and drain connections associated with an engine.
Expand Down
4 changes: 2 additions & 2 deletions library/objective-c/EnvoyEngineImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ - (NSString *)dumpStats {
}

- (void)terminate {
terminate_engine(_engineHandle);
terminate_engine(_engineHandle, /* release */ false);
}

- (void)resetConnectivityState {
Expand All @@ -647,7 +647,7 @@ - (void)startObservingLifecycleNotifications {

- (void)terminateNotification:(NSNotification *)notification {
NSLog(@"[Envoy %ld] terminating engine (%@)", _engineHandle, notification.name);
terminate_engine(_engineHandle);
terminate_engine(_engineHandle, /* release */ false);
}

@end
4 changes: 3 additions & 1 deletion test/common/engine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ struct TestEngineHandle {
run_engine(handle_, MINIMAL_TEST_CONFIG.c_str(), level.c_str(), "");
}

void terminate() { terminate_engine(handle_); }
void terminate() { terminate_engine(handle_, /* release */ false); }

~TestEngineHandle() { terminate_engine(handle_, /* release */ true); }
};

class EngineTest : public testing::Test {
Expand Down
Loading