jjj333-p / spam-police

A matrix bot to monitor and respond to investment scam spamming across the matrix platform, for example in rooms with a permanently offline admin.
GNU Affero General Public License v3.0
21 stars 8 forks source link

race condition upon reacting with "banned" after banlisting a user #43

Closed jjj333-p closed 8 months ago

jjj333-p commented 9 months ago

if the bot manages to receive multiple users confirming at once, it will banlist twice and try to react twice causing the bot to crash and restart image

Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: MatrixHttpClient (REQ-64490) {
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   errcode: 'M_DUPLICATE_ANNOTATION',
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   error: "Can't send same reaction twice"
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: }
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: /home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/http.js:95
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:         throw new MatrixError_1.MatrixError(errBody, response.statusCode);
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:               ^
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: MatrixError: M_DUPLICATE_ANNOTATION: Can't send same reaction twice
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     at doHttpRequest (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/http.js:95:15)
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32)
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32)
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32) {
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   body: {
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     errcode: 'M_DUPLICATE_ANNOTATION',
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:     error: "Can't send same reaction twice"
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   },
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   statusCode: 400,
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   errcode: 'M_DUPLICATE_ANNOTATION',
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   error: "Can't send same reaction twice",
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]:   retryAfterMs: undefined
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: }
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 snap[721641]: Node.js v18.18.0
Oct 01 14:30:24 snapshot-115842185-debian-2gb-hil-1 systemd[1]: spam-police.service: Main process exited, code=exited, status=1/FAILURE
jjj333-p commented 9 months ago

especially causes issues when the homeserver or network is lagging and therefore multiple people react to try and trigger the bot and it ends up all happening at once

Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-23881) Error: ESOCKETTIMEDOUT
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.<anonymous> (/home/joseph/spam-police/node_modules/request/request.js:816:19)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.emit (node:events:517:28)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emitRequestTimeout (node:_http_client:847:9)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emit (node:events:529:35)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Socket._onTimeout (node:net:598:8)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at listOnTimeout (node:internal/timers:569:17)
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at process.processTimers (node:internal/timers:512:7) {
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:   code: 'ESOCKETTIMEDOUT',
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]:   connect: false
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]: }
Oct 15 17:54:45 snapshot-115842185-debian-2gb-hil-1 snap[598]: error !AGeUOyHpLMMrLYAkXW:matrix.org
Oct 15 19:55:59 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-27176) { errcode: 'M_UNKNOWN', error: 'Server is unavailable' }
Oct 15 19:55:59 snapshot-115842185-debian-2gb-hil-1 snap[598]: error !YjAUNWwLVbCthyFrkz:bonifacelabs.ca
Oct 15 19:55:59 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-27173) { errcode: 'M_UNKNOWN', error: 'Server is unavailable' }
Oct 15 19:55:59 snapshot-115842185-debian-2gb-hil-1 snap[598]: error !YjAUNWwLVbCthyFrkz:bonifacelabs.ca
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-29256) Error: ESOCKETTIMEDOUT
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.<anonymous> (/home/joseph/spam-police/node_modules/request/request.js:816:19)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.emit (node:events:517:28)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emitRequestTimeout (node:_http_client:847:9)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emit (node:events:529:35)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Socket._onTimeout (node:net:598:8)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at listOnTimeout (node:internal/timers:569:17)
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at process.processTimers (node:internal/timers:512:7) {
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:   code: 'ESOCKETTIMEDOUT',
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:   connect: false
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]: }
Oct 15 20:49:43 snapshot-115842185-debian-2gb-hil-1 snap[598]: error !AGeUOyHpLMMrLYAkXW:matrix.org
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-29263) Error: ESOCKETTIMEDOUT
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.<anonymous> (/home/joseph/spam-police/node_modules/request/request.js:816:19)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at ClientRequest.emit (node:events:517:28)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emitRequestTimeout (node:_http_client:847:9)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Object.onceWrapper (node:events:631:28)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at TLSSocket.emit (node:events:529:35)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at Socket._onTimeout (node:net:598:8)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at listOnTimeout (node:internal/timers:569:17)
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at process.processTimers (node:internal/timers:512:7) {
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:   code: 'ESOCKETTIMEDOUT',
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]:   connect: false
Oct 15 20:50:43 snapshot-115842185-debian-2gb-hil-1 snap[598]: }
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixHttpClient (REQ-32990) {
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   errcode: 'M_DUPLICATE_ANNOTATION',
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   error: "Can't send same reaction twice"
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: }
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: /home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/http.js:95
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:         throw new MatrixError_1.MatrixError(errBody, response.statusCode);
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:               ^
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: MatrixError: M_DUPLICATE_ANNOTATION: Can't send same reaction twice
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at doHttpRequest (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/http.js:95:15)
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32)
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32)
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     at async descriptor.value (/home/joseph/spam-police/node_modules/matrix-bot-sdk/lib/metrics/decorators.js:19:32) {
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   body: {
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     errcode: 'M_DUPLICATE_ANNOTATION',
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:     error: "Can't send same reaction twice"
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   },
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   statusCode: 400,
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   errcode: 'M_DUPLICATE_ANNOTATION',
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   error: "Can't send same reaction twice",
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]:   retryAfterMs: undefined
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: }
Oct 16 00:36:02 snapshot-115842185-debian-2gb-hil-1 snap[598]: Node.js v18.18.0
Oct 16 00:36:03 snapshot-115842185-debian-2gb-hil-1 systemd[1]: spam-police.service: Main process exited, code=exited, status=1/FAILURE