Closed gmittal closed 7 years ago
Checked the Firebase and mailroom handlers, and none of them are returning duplicate messages. I also checked the communications module. This has to be an issue with either the carrier or Twilio.
Found this: https://support.twilio.com/hc/en-us/articles/223181768-Why-did-the-person-I-sent-a-message-to-get-duplicate-messages-
Will check the Twilio logs.
Alright, so the Twilio Messaging Logs do show duplicate messages, which means that it's an issue somewhere on our end. I have no clue where in the pipeline it is though. Also, this only happens sometimes...
@ankitr @tejpalv8 @srustagi maybe we can each dig around and that'll increase the chances of finding the bug.
As @tejpalv8 requested, it's likely in the following files:
./static/js/main.js
./app.js
ISSUE FOUND (I hope): The keypress event listener that sends a message when you press the enter key in the volunteer console is firing multiple times for no reason, which is why this issue is happening. Patching now.
EDIT: Not the actual source of the issue. The problem is somewhere else. Also I realized that the Mailroom log would also be reporting multiple messages being sent if the issue were to be on our end. But, message success events being logged don't show duplicates, which means this has to be an issue on Twilio's end.
Testing each part of the pipeline.
I think I've found the real source of the issue: the mailroom Firebase real-time handler. It might have to do with the multi-threaded/asynchronous nature of the Node ecosystem. But I did some experiments and discovered the Firebase handler is logging multiple events, but the Twilio/SendGrid modules aren't.
Back to patching.
The easiest way to fix this might be to just have volunteer send a simple POST request forcing Mailroom to check the Firebase for new messages instead of running a realtime listener in Node.
Well, turns out the bug was really silly, and that there were actually two mailrooms running at the same time (except on different computers — one locally and one on the Copilot server) that was causing duplicates to be sent.
This shouldn't happen. We need to isolate this as either a Firebase, Twilio, or mailroom problem. I suspect it's an issue with the number of Firebase listeners listening at the same location (there are probably two that receive one message each time something is changed).