moov-io / rtp20022

ISO20022 messages in Go for Real Time Payments (RTP)
Apache License 2.0
40 stars 9 forks source link

Fix: Ensure Unique AdmnMessageID() Generation #59

Closed mohdjishin closed 4 months ago

mohdjishin commented 4 months ago

Updated the AlphaSerialNumber function to guarantee unique message ID generation even when multiple IDs are created simultaneously. By eliminating the dependency on the current time, this fix ensures that message IDs remain distinct regardless of generation timing. This adjustment mitigates potential conflicts in message identification. This function is called inside AdmnMessageID(). (The issue will occur when you have two sets of queues and you are trying to echo at the same time in both queues. Generated message IDs will be exactly the same if they depend on time.)

adamdecaf commented 4 months ago

I like this, but we knew that time based sequences will conflict. Random numbers will still conflict and will produce out-of-sequence values, which may be unexpected. Perhaps we offer a version of these ID functions which take a generator function.

adamdecaf commented 4 months ago

Thanks for opening these PR's. I've opened https://github.com/moov-io/rtp20022/pull/61 which is a bit more generic and applies to every serial number as they all need this fix. I've included a serial generator using crypto/rand as well.