Skip to content

Update mqtt.js#106

Open
lwkoon wants to merge 1 commit intoliamcottle:masterfrom
lwkoon:patch-1
Open

Update mqtt.js#106
lwkoon wants to merge 1 commit intoliamcottle:masterfrom
lwkoon:patch-1

Conversation

@lwkoon
Copy link

@lwkoon lwkoon commented Jul 16, 2025

wait time for insert and update

wait time for insert and update
Copy link

@cracknel cracknel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 33 and 216 should keep official MQTT server address.

I guess you are trying to avoid some errors caused by rapidly writing to the DB?

You have not initialized maxRetries.

Personally I would use a random wait between 100 and 300ms. 100ms should be enough for previous database write to finish and will also keep the next writes at some distance from each other. Using a fixed wait will just pause the next writes and throw the same exception when you resume processing them.

A queue mechanism would be a better approach.

@lwkoon
Copy link
Author

lwkoon commented Jul 17, 2025

Line 33 and 216 should keep official MQTT server address.

I guess you are trying to avoid some errors caused by rapidly writing to the DB?

You have not initialized maxRetries.

Personally I would use a random wait between 100 and 300ms. 100ms should be enough for previous database write to finish and will also keep the next writes at some distance from each other. Using a fixed wait will just pause the next writes and throw the same exception when you resume processing them.

A queue mechanism would be a better approach.

It solved my problem below:-

951 // create or update node in db
952 try {
→ 953 await prisma.node.upsert(
Unique constraint failed on the constraint: nodes_node_id_key
at _n.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:122:6927)
at _n.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:122:6235)
at _n.request (/app/node_modules/@prisma/client/runtime/library.js:122:5919)
at async l (/app/node_modules/@prisma/client/runtime/library.js:131:9116)
at async MqttClient. (/app/src/mqtt.js:953:17) {
code: 'P2002',
clientVersion: '5.16.1',
meta: { modelName: 'Node', target: 'nodes_node_id_key' }
}
PrismaClientKnownRequestError:
Invalid prisma.node.upsert() invocation in
/app/src/mqtt.js:953:35

950
951 // create or update node in db
952 try {
→ 953 await prisma.node.upsert(
Unique constraint failed on the constraint: nodes_node_id_key
at _n.handleRequestError (/app/node_modules/@prisma/client/runtime/library.js:122:6927)
at _n.handleAndLogRequestError (/app/node_modules/@prisma/client/runtime/library.js:122:6235)
at _n.request (/app/node_modules/@prisma/client/runtime/library.js:122:5919)
at async l (/app/node_modules/@prisma/client/runtime/library.js:131:9116)
at async MqttClient. (/app/src/mqtt.js:953:17) {
code: 'P2002',
clientVersion: '5.16.1',
meta: { modelName: 'Node', target: 'nodes_node_id_key' }
}
PrismaClientKnownRequestError:

@lwkoon
Copy link
Author

lwkoon commented Jul 17, 2025

Line 33 and 216 should keep official MQTT server address.

yes author can modify the line, that's just for my forked version

@lwkoon lwkoon requested a review from cracknel July 17, 2025 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants