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

HH-217737 fix fork workers race conditions #727

Merged
merged 1 commit into from
Aug 27, 2024
Merged

HH-217737 fix fork workers race conditions #727

merged 1 commit into from
Aug 27, 2024

Conversation

712u3
Copy link
Contributor

@712u3 712u3 commented Aug 22, 2024

frontik/app.py Outdated
if self.worker_state.single_worker_mode:
self.worker_state.master_done.value = True
def deinit(self) -> None:
if isinstance(self.service_discovery, MasterServiceDiscovery):
Copy link
Contributor

Choose a reason for hiding this comment

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

это ж можно на уровне реализаций разрулить?

app_name: str,
) -> None:
self.with_consul: bool = with_consul
class MasterServiceDiscovery:
Copy link
Contributor

@a-pertsev a-pertsev Aug 22, 2024

Choose a reason for hiding this comment

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

а почему не стал делать интерфейс который оба класса имплементят?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

пересечение маленькое
сделал ща, можешь посмотреть как получилось

frontik/app.py Outdated
with_consul = self.worker_state.single_worker_mode and options.consul_enabled
self.make_service_discovery(self.worker_state.init_shared_data, with_consul)
if isinstance(self.service_discovery, MasterServiceDiscovery):
self.service_discovery.register_service()
Copy link
Contributor

Choose a reason for hiding this comment

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

и тут можно унести if на уровень реализации

resend_dict: dict = field(default_factory=lambda: {}) # pid: flag
terminating: bool = False
single_worker_mode: bool = True
init_shared_data: dict = field(default_factory=lambda: {})
Copy link
Contributor

Choose a reason for hiding this comment

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

звучит как глагол-метод

frontik/app.py Outdated
self.asgi_app.http_client_factory = self.http_client_factory

if self.worker_state.single_worker_mode:
self.worker_state.master_done.value = True
Copy link
Contributor

Choose a reason for hiding this comment

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

а что это вообще значит - master_done?
вот там выше в fork-функции тоже проставляется True, какая логика?

Copy link
Contributor Author

@712u3 712u3 Aug 22, 2024

Choose a reason for hiding this comment

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

в системной ручке /статус проверка что воркеры стартанули и мастер отработал
это флаг мастера

тут ставится если синглпроцесс режим

@712u3 712u3 force-pushed the HH-217737 branch 2 times, most recently from 03f1731 to 993aa92 Compare August 22, 2024 12:11
frontik/app.py Outdated Show resolved Hide resolved
frontik/app.py Outdated
request_balancer_builder = RequestBalancerBuilder(
self.upstream_manager.get_upstreams(),
self.service_discovery.get_upstreams_unsafe(), # very very bad
Copy link
Member

Choose a reason for hiding this comment

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

зачем unsafe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

в названии?

ну потому что мы выдаем ссылку на священные мутабельные апстримы и если кто-то их поменяет то может клиент сломаться который при каждом запросе по ним бегает

или он сам их поменяет 😱

Copy link
Member

Choose a reason for hiding this comment

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

а нельзя какие-то потокобезопасные коллекции использовать или обернуть методы в локи?
что интересно, при отказе от gil они хотят явно сделать некоторые операции потокобезопасными: python/cpython#112075 (сейчас, насколько я понимаю, эти операции являются безопасными неявно из-за gil)

frontik/process.py Outdated Show resolved Hide resolved
frontik/process.py Outdated Show resolved Hide resolved
frontik/handler.py Outdated Show resolved Hide resolved
frontik/app.py Outdated Show resolved Hide resolved
frontik/server.py Outdated Show resolved Hide resolved
@712u3 712u3 force-pushed the HH-217737 branch 2 times, most recently from 1fc9068 to 10ebf14 Compare August 25, 2024 17:13
frontik/app.py Outdated Show resolved Hide resolved
@@ -424,6 +424,10 @@ async def _execute_page(self) -> None:
assert self.route.dependant.call is not None
returned_value: ReturnedValue = await self.route.dependant.call(**values)

# It is very important to set f_request=None, without this the variable will be deleted only at the next gc call
Copy link
Member

Choose a reason for hiding this comment

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

тока не при следующем gc, а при выходе из метода, потому что питон решит, что значение больше не нужно.

не хочешь f_request подвинуть выше? или он ничего тяжёлого, кроме self, не держит? или values внутри всё равно на f_request ссылается?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

выше плохо да, он нужен в валуесах и в route.dependant.call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

вроде правильно написал
"ставим ноне, тк если не поставим то только на некст гц удалится"

frontik/server.py Outdated Show resolved Hide resolved
@hhrelease hhrelease merged commit 0f56b5e into master Aug 27, 2024
1 check passed
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