Skip to content
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

[PR] Post k8s-events properly from multiple threads (thread-safe) #148

Closed
kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Closed

[PR] Post k8s-events properly from multiple threads (thread-safe) #148

kopf-archiver bot opened this issue Aug 18, 2020 · 0 comments
Labels
archive bug Something isn't working

Comments

@kopf-archiver
Copy link

kopf-archiver bot commented Aug 18, 2020

A pull request by nolar at 2019-07-14 17:55:36+00:00
Original URL: zalando-incubator/kopf#148
Merged by nolar at 2019-07-16 10:09:40+00:00

Part of an effort to make Kopf-based operators more stable and resilient.

Issue : #142 #136
Related: #128

Description

When k8s-event-posting was moved to a background task (#125), some asyncio-related tasks were made way to complicated (multiple dynamically created loggers) and implemented improperly (non-thread-safe put_nowait() when used across threads).

The non-thread-safeness made some k8s-events not posted as soon as it was possible, but waiting for few seconds until something happens on an asyncio event-loop (because put_nowait() does not wake up the event-loop). And it was failing of debug mode was used.

This has become important since #128 — as not only Kopf's internal routines, but also the sync-handlers (which run in a thread-pool) could log INFO+ messages, which should be posted to k8s.

This PR simplifies the solution to one and only one logger (and therefore one and only one handler), and by posting all k8s-events synchronously but instantly via one and only one function (enqueue()).

In that function (enqueue()), one of the thread-safe methods is used to put an event to a queue: either the same-threaded method (thread-safe by definition), or cross-threaded method (explicitly thread-safe).

Types of Changes

  • Refactor/improvements
@kopf-archiver kopf-archiver bot closed this as completed Aug 18, 2020
@kopf-archiver kopf-archiver bot changed the title [archival placeholder] [PR] Post k8s-events properly from multiple threads (thread-safe) Aug 19, 2020
@kopf-archiver kopf-archiver bot added the bug Something isn't working label Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
archive bug Something isn't working
Projects
None yet
Development

No branches or pull requests

0 participants