Page 1 of 1

Same notification received twice

Posted: 12 May 2021, 17:49
by lordalx
For a reported bug, I start thinking that a single notification could be received twice by the client.
My notification is related to taking ressources and for some weird reason, the player reported the ressources was taken twice.
Going through the replay of the game, there is no such cases and ressources are correctly taken, used and displayed.

Due to the client/server architecture, could some corner case exists such as the following one ?
  • Server send a notification to all players, It goes through internet, so maybe some acknowledgement exists.
    At the ends, the server surely needs to save the last notification send to a player in case of connection issues.
  • Player1 receives and handle the notifications, aknowledge it and the server records the last notification.
  • Player2 receives and handle the notifications, aknowledge it, but the aknowledgement never reach the server due to connection time out or something similar
  • Since Server don't get any acknowledgement from Player2, it retries to send the same notification again which this time succeed and is properly aknowledged, but is applied twice for Player2
Since the arguments from a received notification holds an 'uid' field, it can be easy to check on the <game>.js that the received differs from the last handled uid before handling it... but such a feature isn't it already part of the BGA framework internal checks?

Code: Select all

        notif_myNotif: function(args) {
            if (this.prev_notif_uid == args.uid) return;
            // manage the notification at UI level
            this.prev_notif_uid = args.uid;
        },
Does it makes sense ? I can't find in the table database any field related to notification uid apart from the gamelog table within field gamelog_notification. For instance : [{"uid":"609bd1460d552","type":"messages","log":"$...

I think I faced myself such case of double notification for other games when connecting from multiple devices to mobile phone.

Related bug : boardgamearena.com/bug?id=40992

Re: Same notification received twice

Posted: 12 May 2021, 19:20
by robinzig
I'm still new to the BGA framework, but unless there is some important undocumented feature in the framework, there is no request sent from the client to the server to "acknowledge" the receipt of a notification. As far as I can see, the only times clients communicate with the server during a game, other than players refreshing or first going to the game page, are when your game code explicitly sends Ajax requests in response to player actions. There's no reason for the server to care whether a notification was "received" by the client.

So something else must be behind this bug, I'm afraid.

Re: Same notification received twice

Posted: 12 May 2021, 22:42
by Victoria_La
Its likely not the case with multiple notifications but maybe multiple action that have not correctly stopped?
Or sometime you can have rogue state stransition (i.e you transition to states twice in the same action) by ommitting some return
after transition, it can cause some weird issues, i.e.

if (foo) nextState('a')
nextState('b')

Re: Same notification received twice

Posted: 13 May 2021, 08:17
by lordalx
If it was related to double notification or transition from the backend php, this should be visible in the replay as well, which is not the case. :|

Re: Same notification received twice

Posted: 13 May 2021, 08:46
by RicardoRix
maybe you should do something in this:

Code: Select all

 if (this.prev_notif_uid == args.uid) return;
so that you know it's occurring, otherwise you may have fixed the bug but not know that it's actually happening.

In the notification, if you set values equal to the argument, like the score say, then it will work regardless of how many times a notification occurs. It's possible that most times devs handle it like this and so no-one would ever know if a spurious 2nd notification happens.

Re: Same notification received twice

Posted: 13 May 2021, 08:55
by lordalx
I fully agree, it's rather a workaround to prevent something unexpected to happen than a true bug fix.

I'm wondering is there is a way to report in the server's log that such a situation... Or if i'm looking in the wrong direction

Re: Same notification received twice

Posted: 13 May 2021, 17:23
by RicardoRix
is it plausable that the id could change each time? If so, you could add your own id to the args.

I've never used the logging function before, but this page suggests to use php self::warn(), but you are on the client side.... :/
http://en.doc.boardgamearena.com/Studio_logs

Re: Same notification received twice

Posted: 14 May 2021, 06:42
by lordalx
Thanks,

since it's not available from the client, here is a way to do it :

from the <game>.action.php

Code: Select all

public function client_warning()
{ // when the client report a warning to the server to trace some unexpected event
  self::setAjaxMode();
  $log = self::getArg('log', AT_alphanum, true);
  $this->game->warn('[UI_WARNING] ' . $log);
  self::ajaxResponse( );
}
from the <game>.js

Code: Select all

notif_Xxx: function(args) {
    if (this.prev_notif_uid == args.uid) {
        this.ajaxcallwrapper('client_warning', {log: "spurious notifification: "+args.uid});
        // return; // FIXME: return only if reported through production log and confirmed as an issue
    }
    // notification handler code 
},

Re: Same notification received twice

Posted: 16 May 2021, 04:32
by paramesis
If this is still an issue you're trying to diagnose, it looks like you may have multiple dojo subscriptions to the same notification.

In many of my projects, I have notifications handled by a class defined in a separate file, an instance of which is created when the page loads. If the page was reloaded by a framework undo, the notification effects would occur twice. I found the reason was because the original subscriptions were still listening for notifications and the new Notification Manager instance was creating duplicate subscriptions. My solution was to save the handles created by the subscribe function and create a destroy function that would unsubscribe from all notifications:

Code: Select all

NotificationManager.prototype.setupNotifications = function() {

    this.subscriptions.push( dojo.subscribe( 'movePlayer', this, "notif_movePlayer" ) );
    this.game.notifqueue.setSynchronous( 'movePlayer', 1000 );

...

Code: Select all

NotificationManager.prototype.destroy = function() {
    dojo.forEach( this.subscriptions, dojo.unsubscribe );
};

Re: Same notification received twice

Posted: 17 May 2021, 12:28
by lordalx
Thanks for you suggestion, but I still have a pretty simple notification system through the setupNotificaton from the template, only called once.

I have the first result from yesterday exposure and the problems spawn multiple times (with not any related bug reports ;p)
It's funny to see that it happened on the same table twice at the same time for several players (2 out of 3).

Code: Select all

17/05 11:58:26 [warning] [T173098505] [83964795/Shapps] [UI_WARNING] spurious notifification 60a23e41451c4
17/05 11:58:26 [warning] [T173098505] [90000245/sskyuk] [UI_WARNING] spurious notifification 60a23e41451c4
Meaning both players received twice the same uid 60a23e41451c4.

Still under investigation...