Skip to content

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

@jjiang10-sv

Description

@jjiang10-sv

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions