-
Notifications
You must be signed in to change notification settings - Fork 5.3k
wasm: fix network leak #13836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasm: fix network leak #13836
Changes from all commits
bddc2a7
7d9cdd1
7ff34b7
b38e587
3f20a04
2405e4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -858,11 +858,7 @@ BufferInterface* Context::getBuffer(WasmBufferType type) { | |
| void Context::onDownstreamConnectionClose(CloseType close_type) { | ||
| ContextBase::onDownstreamConnectionClose(close_type); | ||
| downstream_closed_ = true; | ||
| // Call close on TCP connection, if upstream connection closed or there was a failure seen in | ||
| // this connection. | ||
| if (upstream_closed_ || getRequestStreamInfo()->hasAnyResponseFlag()) { | ||
| onCloseTCP(); | ||
| } | ||
| onCloseTCP(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This whole change could be basically minimized to this (i.e. on downstream close, close TCP context). I don't think we can remove upstream close event, since it's a breaking change, or that we even need to remove it in order to fix the issue at hand.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In any case, this bug is not unique to Wasm, and I think the proper fix should emit upstream connection close event (again, see: #13856).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, #13856 is not the root cause for #13806, but it results in the same leak. For #13806 the issue is that the upstream close event won't be triggered if the connection to upstream was never established (e.g. connection timeout, connection refused), but once #13856 is fixed, then this event is always triggered if the connection to upstream was established, so I don't see the point in removing it. Like I said originally, this PR should be reduced to "on downstream close event, destroy context" (ideally, we should keep waiting for upstream close if we ever transmitted data in either direction), but without removing the upstream close event.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can reproduce this without TLS.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you share the steps to reproduce so that I can try to debug it?
It might work by accident, but Proxy-Wasm plugins don't officially support "upstream network filters", and I suspect that some things will be broken because of flipped direction and related checks. I'm also pretty sure there are no tests for that use case. Please open an issue if you want to use them as "upstream network filters".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
diff --git a/extensions/stats/plugin.cc b/extensions/stats/plugin.cc
index a051b5d7..2e8dcd87 100644
--- a/extensions/stats/plugin.cc
+++ b/extensions/stats/plugin.cc
@@ -546,6 +546,7 @@ bool PluginRootContext::onDone() {
}
void PluginRootContext::onTick() {
+ LOG_INFO(absl::StrCat("connection_count: ", connection_count, " log_count: ", log_count));
if (request_queue_.empty()) {
return;
}
diff --git a/extensions/stats/plugin.h b/extensions/stats/plugin.h
index 8472d6e8..fba522c2 100644
--- a/extensions/stats/plugin.h
+++ b/extensions/stats/plugin.h
@@ -260,6 +260,9 @@ class PluginRootContext : public RootContext {
::Wasm::Common::RequestInfo* request_info);
void deleteFromRequestQueue(uint32_t context_id);
+ int64_t log_count = 0;
+ int64_t connection_count = 0;
+
protected:
const std::vector<MetricTag>& defaultTags();
const std::vector<MetricFactory>& defaultMetrics();
@@ -333,6 +336,8 @@ class PluginContext : public Context {
if (request_info_.request_protocol == ::Wasm::Common::Protocol::TCP) {
request_info_.tcp_connections_closed++;
}
+
+ rootContext()->log_count++;
rootContext()->report(request_info_, true);
};
@@ -361,6 +366,7 @@ class PluginContext : public Context {
request_info_.request_protocol = ::Wasm::Common::Protocol::TCP;
request_info_.tcp_connections_opened++;
rootContext()->addToRequestQueue(id(), &request_info_);
+ rootContext()->connection_count++;
return FilterStatus::Continue;
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #13929 .
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have high confidence that there's some other issue lurking about error propagation. If this happened under trivial config, it's very likely that more complex config can cause the same leak. We should not expect that upstream connection events are correctly emitted. |
||
| } | ||
|
|
||
| void Context::onUpstreamConnectionClose(CloseType close_type) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.