Skip to content

Commit

Permalink
fix startup issue
Browse files Browse the repository at this point in the history
  • Loading branch information
PudgyPug committed Sep 9, 2024
1 parent 3b6fabb commit c5cd6d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"node-cron": "3.0.2",
"node-fetch": "^2.6.8",
"rfdc": "^1.3.0",
"socket.io-client": "^4.7.5",
"socket.io-client": "4.7.5",
"sqlite3": "^5.0.0",
"streamroller": "^3.1.3",
"tydb": "^0.1.5"
Expand Down
23 changes: 22 additions & 1 deletion src/Data/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ export async function unsubscribeDataSender(
}
const socketClient = socketClients.get(publicKey)
if (socketClient) {
console.log(' red - unsubscribe from node', publicKey)

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
socketClient.emit('UNSUBSCRIBE', config.ARCHIVER_PUBLIC_KEY)
socketClient.close()
socketClients.delete(publicKey)
Expand All @@ -192,7 +193,7 @@ export async function unsubscribeDataSender(
export function initSocketClient(node: NodeList.ConsensusNodeInfo): void {
if (config.VERBOSE) Logger.mainLogger.debug('Node Info to socket connect', node)
const socketClient = io(`http://${node.ip}:${node.port}`, {
transports: ['websocket','polling'],
transports: ['websocket'],
reconnection: true,
reconnectionAttempts: Infinity,
reconnectionDelay: 1000,
Expand All @@ -202,8 +203,26 @@ export function initSocketClient(node: NodeList.ConsensusNodeInfo): void {
socketClients.set(node.publicKey, socketClient)

let archiverKeyisEmitted = false
socketClient.on('connect_error', (error) => {
console.error(' red - Connection error:', error);
if (socketClient.active) {
console.log(' red - temporary failure, the socket will automatically try to reconnect');
} else {
console.log(' red - Connection denied by the server. Trying to reconnect');
socketClient.connect()
}
});

socketClient.on('error', (error) => {
console.error(' red - Socket error:', error);
});

socketClient.on('connect_timeout', () => {
console.log(' red - Connection timed out');
});

socketClient.on('connect', () => {
console.log(' red - connected to node', node.ip, node.port)

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
Logger.mainLogger.debug(
`${!archiverKeyisEmitted ? 'New connection' : 'Reconnection'} to consensus node ${node.ip}:${
node.port
Expand All @@ -218,10 +237,12 @@ export function initSocketClient(node: NodeList.ConsensusNodeInfo): void {
})

socketClient.once('disconnect', async () => {
console.log(' red - disconnected from node', node.ip, node.port)

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
Logger.mainLogger.debug(`Connection request is refused by the consensor node ${node.ip}:${node.port}`)
})

socketClient.on('DATA', (data: string) => {
console.log(' red - data received from node', node.ip, node.port)

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
const newData: DataResponse<P2PTypes.SnapshotTypes.ValidTypes> & Crypto.TaggedMessage =
StringUtils.safeJsonParse(data)
if (!newData || !newData.responses) return
Expand Down

0 comments on commit c5cd6d1

Please sign in to comment.