libevent: event_enable_debug_logging() not to be used after creating event base #27182

issue stickies-v openend this issue on March 1, 2023
  1. stickies-v commented at 10:58 am on March 1, 2023: contributor

    Raising this issue on behalf of @hebasto who identified the potential problem as well as dug into the docs.

    The logging RPC method, through UpdateHTTPServerLogging() calls the libevent function event_enable_debug_logging(). The libevent documentation states that “You must make any changes to these settings before you call any other part of the Libevent library. If you don’t, Libevent could wind up in an inconsistent state.”, and the headers similarly state that “This is a global setting; if you are going to call it, you must call this before any calls that create an event-base. You must call it before any multithreaded use of Libevent.”

    It was introduced in #10150, where reference is made to the libevent 2.1 release notes that state that “You can now turn on debug logs at runtime using a new function, event_enable_debug_logging().”, making this a seemingly safe implementation.

    It appears that:

    1. Bitcoin Core’s usage of event_enable_debug_logging() violates the current libevent documentation
    2. either there is inconsistency between the libevent 2.1 release notes and the documentation, or the behaviour of event_enable_debug_logging() has been changed after 2.1 in a backwards-incompatible way
    3. this currently does not seem to be causing any real-world issues

    Even though it seems like there are currently no actual problems, it’s probably something to be mindful of and ideally resolve, either by disabling toggling libevent debug logging at runtime or verifying that our current usage is indeed safe and will not lead to issues now or in the future.

  2. stickies-v renamed this:
    libevent: event_enable_debug_logging() not to be used after creating of event base
    libevent: event_enable_debug_logging() not to be used after creating event base
    on Mar 1, 2023
  3. fanquake added the label Upstream on Mar 1, 2023
  4. fanquake commented at 12:08 pm on March 8, 2023: member

    Looks like, according to the upstream reply, this is not actually a problem at all, and the documentation is incorrect/outdated:

    I don’t see any possible issues with calling event_enable_debug_logging after creating of event_base, and basically anytime (except for maybe a TSan warning, since the code is not uses proper atomics, but this should not be a problem, but it can leads to loosing few messages before/after calling event_enable_debug_logging if you have concurrent libevent loop) That said that you are safe to use it in anytime.

    So I think we can close this, and potentially follow up with documentation updates upstream?

  5. hebasto commented at 1:43 pm on March 8, 2023: member

    So I think we can close this, and potentially follow up with documentation updates upstream?

    Agree.

  6. stickies-v closed this on Mar 8, 2023

  7. hebasto commented at 2:08 pm on March 8, 2023: member
    @stickies-v Thanks for making this issue clear!
  8. stickies-v commented at 2:28 pm on March 8, 2023: contributor
    Agreed, looks like we don’t need to take any further action. I’ll follow up upstream next week. Closed.
  9. bitcoin locked this on Mar 7, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me