Skip to content

[NotificationService] Cannot use one EmbeddedNotificationClient instance in multiple threads #351

@jiangxin369

Description

@jiangxin369

Describe the bug

Cannot use one EmbeddedNotificationClient instance in multiple threads.

Your environment

Operating system

Database

Python version

To Reproduce

    def test_create_client_multiple_threads(self):
        import threading
        from notification_service.embedded_notification_client import EmbeddedNotificationClient
        from notification_service.event import Event, EventKey

        client = EmbeddedNotificationClient(server_uri="localhost:50052", namespace='default', sender='sender')

        def send_event():
            event = Event(event_key=EventKey('key1'), message='a')
            client.send_event(event)
            print(client.sequence_number)
        threads = []
        for i in range(100):
            thread = threading.Thread(target=send_event)
            threads.append(thread)
        for t in threads:
            t.start()
        for t in threads:
            t.join()

Expected behavior

100 events sent.

Actual behavior

less than 100 events sent.

Screenshots

Additional context

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