-
Notifications
You must be signed in to change notification settings - Fork 2k
tls: yield downstream read retries to the event loop [Backport to 5.0] #12141
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
base: 5.0
Are you sure you want to change the base?
Changes from all commits
52dc27c
dc675fa
86a2f07
9ef9b18
854f656
f30e3a3
a4e27cb
1e2a2a4
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 |
|---|---|---|
|
|
@@ -162,7 +162,7 @@ static inline int io_tls_event_switch(struct flb_tls_session *session, | |
| event = &session->connection->event; | ||
| event_loop = session->connection->evl; | ||
|
|
||
| if ((event->mask & mask) == 0) { | ||
| if ((event->mask & (MK_EVENT_READ | MK_EVENT_WRITE)) != mask) { | ||
| ret = mk_event_add(event_loop, | ||
| event->fd, | ||
| FLB_ENGINE_EV_THREAD, | ||
|
|
@@ -345,12 +345,19 @@ int flb_tls_set_client_thumbprints(struct flb_tls *tls, const char *thumbprints) | |
|
|
||
| int flb_tls_net_read(struct flb_tls_session *session, void *buf, size_t len) | ||
| { | ||
| int event_driven; | ||
| time_t timeout_timestamp; | ||
| time_t current_timestamp; | ||
| struct flb_tls *tls; | ||
| int ret; | ||
|
|
||
| tls = session->tls; | ||
| event_driven = FLB_FALSE; | ||
|
|
||
| if (session->connection->type == FLB_DOWNSTREAM_CONNECTION && | ||
| MK_EVENT_IS_REGISTERED((&session->connection->event))) { | ||
| event_driven = FLB_TRUE; | ||
| } | ||
|
|
||
| if (session->connection->net->io_timeout > 0) { | ||
| timeout_timestamp = time(NULL) + session->connection->net->io_timeout; | ||
|
|
@@ -365,6 +372,14 @@ int flb_tls_net_read(struct flb_tls_session *session, void *buf, size_t len) | |
| current_timestamp = time(NULL); | ||
|
|
||
| if (ret == FLB_TLS_WANT_READ) { | ||
| if (event_driven) { | ||
| if (io_tls_event_switch(session, MK_EVENT_READ) == -1) { | ||
| return -1; | ||
| } | ||
|
|
||
| return FLB_TLS_WANT_READ; | ||
| } | ||
|
|
||
| if (timeout_timestamp > 0 && | ||
| timeout_timestamp <= current_timestamp) { | ||
| return ret; | ||
|
|
@@ -373,6 +388,14 @@ int flb_tls_net_read(struct flb_tls_session *session, void *buf, size_t len) | |
| goto retry_read; | ||
| } | ||
| else if (ret == FLB_TLS_WANT_WRITE) { | ||
| if (event_driven) { | ||
| if (io_tls_event_switch(session, MK_EVENT_READ | MK_EVENT_WRITE) == -1) { | ||
|
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.
When a downstream TLS read returns Useful? React with 👍 / 👎. |
||
| return -1; | ||
| } | ||
|
|
||
| return FLB_TLS_WANT_WRITE; | ||
| } | ||
|
|
||
| goto retry_read; | ||
| } | ||
| else if (ret < 0) { | ||
|
|
@@ -382,6 +405,10 @@ int flb_tls_net_read(struct flb_tls_session *session, void *buf, size_t len) | |
| return -1; | ||
| } | ||
|
|
||
| if (event_driven && io_tls_event_switch(session, MK_EVENT_READ) == -1) { | ||
| return -1; | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When secure-forward is enabled and
buffer_chunk_sizeis configured below 1023,conn->bufis only that configured size, butcheck_ping()calls this helper withsize == 1023, soflb_io_net_read()can write past the end ofconn->bufbefore msgpack validation runs. Please capavailbyconn->buf_size - conn->buf_lenor grow the connection buffer before reading the PING.Useful? React with 👍 / 👎.