status-im / status-console-client

Status messaging console user interface
Mozilla Public License 2.0
10 stars 2 forks source link

Sending messages concurrently using messenger.Send sometimes fails #102

Closed dshulyak closed 5 years ago

dshulyak commented 5 years ago

In https://github.com/status-im/status-scale/pull/32 1000 of messages are sent concurrently, sometimes leads to message uniqueness failure:

--- FAIL: TestHistoryDownload (31.27s) require.go:794: Error Trace: mailservers_test.go:58 Error: Received unexpected error: failed to save msg with payload 603: failed to save the message: message with given ID already exist failed to save msg with payload 707: failed to save the message: message with given ID already exist

dshulyak commented 5 years ago

There is a race condition between saving message in Send method, and saving message when receiving from Stream. Stream ignores uniqueness failures, and Send doesn't. We should either do whole Send inside of the same tx so that db connection is not released, and Send always will be able to save message before Stream will get access to db connection. Or remove saving messages in Send at all.