Page 1 of 1

Event callback is called three times for each event

Posted: Fri Feb 12, 2016 6:19 am
by Sobiru
Hello,
I have this weird bug which the callback is triggered three times on each event like "Login" or "Logout".
I'm using sessionId to log my users in and when I refresh the page which does a "Logout" > "Login", I get 6 (3 for each) callbacks.
I put a

Code: Select all

Debug.WriteLine()
in my callback handler and this is the result for a single refresh.
Weired bug.png
Weired bug.png (7.46 KiB) Viewed 8200 times
I can't figure out what's wrong. Anyone else experience this?

Re: Event callback is called three times for each event

Posted: Fri Feb 12, 2016 10:21 am
by Kent Briggs
Print out all the parameters for the event (Event, Player, SessionID, Time) and see if those are all duplicate. Does the Event Log log show multiple logins/logouts? What happens if you do not refresh the page and log in and out normally?

Re: Event callback is called three times for each event

Posted: Fri Feb 12, 2016 6:31 pm
by Sobiru
Kent Briggs wrote:Print out all the parameters for the event (Event, Player, SessionID, Time) and see if those are all duplicate. Does the Event Log log show multiple logins/logouts? What happens if you do not refresh the page and log in and out normally?
Ok, I printed out all the posted parameters and they seem to be duplicated. Here is the output from one login attempt. ( For some unknown reason "SessionID" variable is empty.)
EventLog.png
EventLog.png (25.21 KiB) Viewed 8196 times
In the event log in the system tab I can see only one login. Here is the screenshot:
EventLog.png
EventLog.png (25.21 KiB) Viewed 8196 times
I've also noticed in the error log in the system tab, I get 3 errors like this for each event. I don't know if this is related or not. Here is the screenshot:
Error Log.png
Error Log.png (13.38 KiB) Viewed 8196 times

Re: Event callback is called three times for each event

Posted: Fri Feb 12, 2016 6:34 pm
by Sobiru
Sorry the first picture is supposed to be the picture on the bottom of the post(the picture with the black frame). Couldn't find an option to edit my post.

Re: Event callback is called three times for each event

Posted: Fri Feb 12, 2016 6:36 pm
by Sobiru
I forgot to mention when I don't use session id and manually login, I see same behvaiour. 3 Callbacks for each event.

Re: Event callback is called three times for each event

Posted: Fri Feb 12, 2016 6:47 pm
by Kent Briggs
Sounds like your web server is returning a "500" error code (even though it accepted the connection anyway) instead of the normal "200" result code. And so the callback routine is making multiple attempts at it. Are you terminating your code in some manner that would cause that? Try just echoing back an "Ok" message, even though that will be ignored. You should also be getting a valid SessionID parameter. I just tested that on my end it works fine.

Re: Event callback is called three times for each event

Posted: Sat Feb 13, 2016 1:42 pm
by Sobiru
Kent Briggs wrote:Sounds like your web server is returning a "500" error code (even though it accepted the connection anyway) instead of the normal "200" result code. And so the callback routine is making multiple attempts at it. Are you terminating your code in some manner that would cause that? Try just echoing back an "Ok" message, even though that will be ignored. You should also be getting a valid SessionID parameter. I just tested that on my end it works fine.
Right on. Somewhere in my event callback handler, I had an async operation. Now even though the async operation was successfully returning result eventually, but for some reason response of web server was 500 error code. I changed that operation to be synchronous and now everything is fine. I don't know if this is an issue with the IIS (where i'm hosting) or something else. But I got to find a way to make it work Async because it's much better for my case.

Re: Event callback is called three times for each event

Posted: Sat Feb 13, 2016 2:28 pm
by Sobiru
I did some further investigating and found out in case of a refresh (with Session ID), you get "Logout" and then "Login" in quick succession. So my async method which was doing an HTTP request to somewhere would throw an exception because it called two times almost at the same time and I wasn't catching that exception. When async method threw an exception, the callback event handler would terminate unexpectedly and return internal server (500) status code and then in reaction to that Poker Mavens Server tries to resend you the event (up to 3 times). To fix my issue, I made sure that my async method would execute only if more than ten minutes has passed since the last request.

So if anyone had the same issue, check your code to see if anywhere in your event callback handler, you have a potential to get an exception and then try to catch/avoid that exception. This was of course an error in my coding and nothing to do with IIS/Poker Mavens server. Thank you @Briggs for guiding me in the right direction.