Skip to content

publish_to_internal_channel is not threadsafe #115

@yuqiuw

Description

@yuqiuw

def publish_to_internal_channel(self, channel_name: str, value: Any = None):

Here's part of the publish_to_internal_channel func :

def publish_to_internal_channel(self, channel_name: str, value: Any = None):     
    ...   
    vals = self._to_publish_internal_channel.get(channel_name)
    if vals is None:
        vals = []
    vals.append(self._object_encoder.encode(value))
    self._to_publish_internal_channel[channel_name] = vals

When multiple threads hitting this function, it could have a race condition where
Thread A gets vals = [1,2,3]
Thread B gets vals = [1,2,3]
Thread A updates it to be [1,2,3,4]
Thread B updates it to be [1,2,3,5]
Here we lost 4 permanently

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions