Skip to content

Sanity checking libevent is initialized#2339

Merged
mattklein123 merged 4 commits intoenvoyproxy:masterfrom
alyssawilk:pthread
Jan 11, 2018
Merged

Sanity checking libevent is initialized#2339
mattklein123 merged 4 commits intoenvoyproxy:masterfrom
alyssawilk:pthread

Conversation

@alyssawilk
Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk commented Jan 10, 2018

We've had a couple of instances of internal Envoy with custom main or custom tests failing to initialize things properly and causing hard to debug timeouts / tsan warnings.

Adding RELEASE_ASSERTs to hopefully catch this earlier and in a more obvious way.

Risk Level: Low
Testing: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Copy Markdown
Member

@ggreenway ggreenway left a comment

Choose a reason for hiding this comment

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

I think the bool should be moved to a class static, the accessor put into the header, and the ASSERT changed to RELEASE_ASSERT (since it will be basically free if the accessor is inline).

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@alyssawilk
Copy link
Copy Markdown
Contributor Author

Sure! I'd only used ASSERT I figured since it is way more likely to affect Googlers (using our internal version of gtest) and this would minimize the impact on everyone else.

@ggreenway
Copy link
Copy Markdown
Member

I think I'm in the minority, but I prefer all ASSERTs to be RELEASE_ASSERT unless it has a large performance impact (like if a bunch of code had to be run to calculate the thing that is being asserted). I'd rather have it abort than run in an unexpected/unsupported state.

ggreenway
ggreenway previously approved these changes Jan 10, 2018
Comment thread source/common/event/dispatcher_impl.cc Outdated
post_timer_(createTimer([this]() -> void { runPostCallbacks(); })),
current_to_delete_(&to_delete_1_) {}
current_to_delete_(&to_delete_1_) {
ASSERT(Libevent::Global::initialized());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, this one should probably also be RELEASE_ASSERT

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.

What are you talking about, I already changed that file! ... facepalm :-P

Comment thread source/common/event/libevent.h Outdated
class Global {
public:
// True if initialized() has been called.
static bool INITIALIZED;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be lower case, this isn't a constant?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: This variable can be private.

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.

Oh, is the CAPS only for contants? I thought it was for all static.
Ignoring the naming conflict, static bool intitialized; is weird and static bool initialized_ isn't correct.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Comment thread source/common/event/libevent.h Outdated

private:
// True if initialized() has been called.
static bool is_initialized;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think is_initialized_ or initialized_ is the correct name, even though it is static:

https://google.github.io/styleguide/cppguide.html#Variable_Names section "Class Data Members", and I didn't see an override in STYLE.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@mattklein123 mattklein123 merged commit 83d4539 into envoyproxy:master Jan 11, 2018
@alyssawilk alyssawilk deleted the pthread branch January 30, 2018 18:47
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
Shikugawa pushed a commit to Shikugawa/envoy that referenced this pull request Mar 28, 2020
This reverts commit 38a2475.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
jpsim added a commit that referenced this pull request Nov 28, 2022
Signed-off-by: GitHub Action <noreply@github.com>

Co-authored-by: jpsim <jpsim@users.noreply.github.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Nov 29, 2022
Signed-off-by: GitHub Action <noreply@github.com>

Co-authored-by: jpsim <jpsim@users.noreply.github.com>
Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants