Anton, Huy!
I noticed one unpleasant feature: In cases where the number of sent SMS is more than the balance, for example, when there is 1000 SMS in the user’s balance and he wants to send 3000, SMS sending does not stop at 1000 but continues to go in minutes and reaches -2000. Even the “Ban” of the user does not help.
Anton didn’t work, tried it in 2 versions and got the message in both:
In the first case, I tried to form a message with less than 160 characters and using Send from file. There were 0.02 units on the user’s balance (each SMS is equal to 0.01), I sent a file with 4 numbers, it didn’t work.
In the second case, I tried to compose an SMS from UNICODE characters and indicate more than 80 characters (so that each SMS contains a total of 2 SMS), and in this case the system responded correctly.
In the first case, I tried to form a message with less than 160 characters and using Send from file. There were 0.02 units on the user’s balance (each SMS is equal to 0.01), I sent a file with 4 numbers, it didn’t work.
In the second case, I tried to compose an SMS from UNICODE characters and indicate more than 80 characters (so that each SMS contains a total of 2 SMS), and in this case the system responded correctly.
In both cases I received: failed user do not have enough credit.
But sometimes it happens, namely, I see that the user’s balance has gone into negative territory, PlaySMS has already sent all messages to the gateway and its balance will constantly go into negative territory. We have to delete messages in Redis, which helps.
I just tested 2000 SMS with the same message, thus having only 1 queue, playSMS successfully blocking this because calculating Balance done before processing any SMS.
But if you send 2000 SMS with different message, thus having 2000 queues in one go, playSMS will process this and balance will be negative. This is because playSMS counting current balance with that per queue, which is under current balance.
So, counting credit/balance is correct, but getting into negative balance is not OK. playSMS need to calculate everything before processing SMS in sendsms(), and in sendsmsd() there must be a check with current realtime balance.
The issue is due to race condition in reading the adhoc credit. The race condition happened because of multiple playSMS daemon reading database. Adhoc credit is temporary credit/balance used by simplerate_hook_rate_cansend() to decide whether the user can continue processing the SMS for delivery or not.
Set this to 1 in web/config.php then calculation should be correct:
// limit the number of queue processed by sendsmsd in one time
$core_config['sendsmsd_queue'] = 1;
In master version I added a check for user’s balance before processing uploaded SMS. I haven’t test it in 1.4.3, but maybe you can just drop replace your feature/sendfromfile/*.php files with this:
You also need to update DB table playsms_featureSendfromfile using this SQL:
The DB update won’t interfere with sendfromfile from 1.4.3, so no need to revert if the test fails.
Hi, Anton!
Thank you for trying to make PlaySMS better.
As for the option to send SMS using “Send from file”, I did not observe such system behavior there.
The user’s balance goes into the negative when working with the API, and such a case has repeatedly happened.
Yes, one step at a time, theres a roadblock in fixing this issue, namely it needs trasactions or some lock, or better logic, when multiple playSMS daemon reading/updating current adhoc balance that is used to allow/restrict SMS processing.
I probably can do the same for now on webservices, to check againts balance before actually process submitted SMS. But that’s not fixing the actual issue.