BentoML icon indicating copy to clipboard operation
BentoML copied to clipboard

bug: Bento Build -- Service.inject_config race condition on BentoMLContainer.config

Open jjiang10-sv opened this issue 6 months ago • 1 comments

Describe the bug

Config updates and service access /_bentoml_sdk/service/factory.py

def inject_config(self) -> None: # ... configuration processing ... existing = t.cast(t.Dict[str, t.Any], BentoMLContainer.config.get()) deep_merge(existing, {"api_server": api_server_config, **rest_config}) BentoMLContainer.config.set(existing) # Updates global config

Looking at the code, there's a potential race condition and config pollution: 1, Global state modification: BentoMLContainer.config.set(existing) modifies global state 2, Service interference: Multiple services calling inject_config() can interfere with each other 3, No isolation: Changes from one service affect others

For example :

Service A calls inject_config()

service_a = Service("service_a") service_a.inject_config() # Updates global BentoMLContainer.config

Service B calls inject_config() later

service_b = Service("service_b") service_b.inject_config() # Gets the already-modified config from Service A!

To reproduce

No response

Expected behavior

No response

Environment

bentoml: 1.4.17 python: 3.11.2

jjiang10-sv avatar Jul 06 '25 05:07 jjiang10-sv

yeah we doesn't handle race condition for it because it won't be run in parallel. Is there any use case you need to build bento in parallel?

frostming avatar Jul 07 '25 01:07 frostming