Skip to content

Commit 3195d06

Browse files
authored
Merge pull request #1305 from ainblockchain/bugfix/platfowner/bugfix
Reduce channel id conflict probability
2 parents f17957b + 2396a74 commit 3195d06

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

event-handler/event-channel-manager.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const EventHandlerError = require('./event-handler-error');
1313
const { EventHandlerErrorCode } = require('../common/result-code');
1414
const BlockchainEvent = require('./blockchain-event');
1515

16+
const CHANNEL_ID_RANDOM_NUMBER_RANGE = 1000;
17+
1618
class EventChannelManager {
1719
constructor(node) {
1820
this.node = node;
@@ -107,7 +109,9 @@ class EventChannelManager {
107109
`The number of event channels exceeds its limit ` +
108110
`(${NodeConfigs.MAX_NUM_EVENT_CHANNELS})`);
109111
}
110-
const channelId = Date.now(); // NOTE: Only used in blockchain
112+
// NOTE: Only used in blockchain
113+
const channelId
114+
= String(Date.now() + Math.floor(Math.random() * CHANNEL_ID_RANDOM_NUMBER_RANGE));
111115
if (this.channels[channelId]) { // TODO(cshcomcom): Retry logic.
112116
webSocket.terminate();
113117
throw new EventHandlerError(EventHandlerErrorCode.DUPLICATED_CHANNEL_ID,

0 commit comments

Comments
 (0)