After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 726455 - Force engines to move after some timeout
Force engines to move after some timeout
Status: RESOLVED FIXED
Product: gnome-chess
Classification: Applications
Component: General
3.10.x
Other Linux
: Normal normal
: ---
Assigned To: Sahil Sareen
gnome-chess-maint
Depends on:
Blocks:
 
 
Reported: 2014-03-16 14:23 UTC by Michael Catanzaro
Modified: 2015-07-15 18:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Testing done (107.48 KB, image/png)
2015-07-13 08:47 UTC, Sahil Sareen
  Details
Prevent a buggy engine from living forever (1.70 KB, patch)
2015-07-13 08:48 UTC, Sahil Sareen
none Details | Review
Prevent a buggy engine from living forever (1.57 KB, patch)
2015-07-13 09:14 UTC, Sahil Sareen
none Details | Review
Prevent a buggy engine from living forever (1.95 KB, patch)
2015-07-15 05:51 UTC, Sahil Sareen
accepted-commit_now Details | Review

Description Michael Catanzaro 2014-03-16 14:23:47 UTC
Right now there is nothing to prevent a buggy engine from living forever without moving, causing the game to appear to hang. We've become robust to every other engine error that I can think of, so we should handle this as well. (This isn't high priority since I've never seen this happen.)

There should be a long timeout (e.g. 30 seconds) after which we attempt to force the engine to move immediately and display a fatal error if it can't.
Comment 1 Michael Catanzaro 2014-06-26 13:22:23 UTC
30s is too long; should be more like 10s
Comment 2 Sahil Sareen 2015-07-10 15:49:06 UTC
(In reply to Michael Catanzaro from comment #0)
> Right now there is nothing to prevent a buggy engine from living forever
> without moving, causing the game to appear to hang. We've become robust to
> every other engine error that I can think of, so we should handle this as
> well. (This isn't high priority since I've never seen this happen.)
> 
> There should be a long timeout (e.g. 30 seconds) after which we attempt to
> force the engine to move immediately and display a fatal error if it can't.

Hi Michael

The fatal error needs to show up as a dialog?
and post the fatal error, I assume we would want to end the game.

Please correct me if you have an alternate approach in mind.
Comment 3 Michael Catanzaro 2015-07-10 16:21:18 UTC
Hi! Instead of displaying a dialog, I would use the existing error reporting mechanism: end the game using ChessResult.BUG, ChessRule.BUG. That displays an infobar with a generic error message about the computer being confused.

To test this, you might be able to stop the chess engine using System Monitor.
Comment 4 Sahil Sareen 2015-07-13 07:54:45 UTC
(In reply to Michael Catanzaro from comment #3)
> Hi! Instead of displaying a dialog, I would use the existing error reporting
> mechanism: end the game using ChessResult.BUG, ChessRule.BUG. That displays
> an infobar with a generic error message about the computer being confused.
> 
> To test this, you might be able to stop the chess engine using System
> Monitor.

Thanks for the inputs Michael, will get back with a patch.
Comment 5 Sahil Sareen 2015-07-13 08:47:53 UTC
Created attachment 307330 [details]
Testing done

Using the system monitor was a good idea, 
but I reduced the engine timeout to 1 second to test this.
Comment 6 Sahil Sareen 2015-07-13 08:48:54 UTC
Created attachment 307331 [details] [review]
Prevent a buggy engine from living forever
Comment 7 Sahil Sareen 2015-07-13 09:14:26 UTC
Created attachment 307333 [details] [review]
Prevent a buggy engine from living forever

The previous patch let the timer move for another 2 seconds after the issue occurred.

Marking that as OBSOL.
Comment 8 Michael Catanzaro 2015-07-13 13:39:51 UTC
Review of attachment 307333 [details] [review]:

Thanks! It looks good, push after fixes:

::: src/gnome-chess.vala
@@ +817,3 @@
     }
 
+    int engine_timeout = 10;

This should be listed at the top of the class, with all the other fields (member variables). I'd name it "engine_timeout_counter."

@@ +829,3 @@
+            engine_timeout -= 1;
+
+            if (engine_timeout <= 0)

The check should be == 0, since it's an error for it ever to be less than 0.
Comment 9 Sahil Sareen 2015-07-13 18:22:10 UTC
(In reply to Michael Catanzaro from comment #8)
> Review of attachment 307333 [details] [review] [review]:
> 
> Thanks! It looks good, push after fixes:
> 
> ::: src/gnome-chess.vala
> @@ +817,3 @@
>      }
>  
> +    int engine_timeout = 10;
> 
> This should be listed at the top of the class, with all the other fields
> (member variables). I'd name it "engine_timeout_counter."

Sure!

> 
> @@ +829,3 @@
> +            engine_timeout -= 1;
> +
> +            if (engine_timeout <= 0)
> 
> The check should be == 0, since it's an error for it ever to be less than 0.

Can I throw an exception for " < 0" case 
    or assert on timeout > 0
and crash the game for such erroneous situations ?
Comment 10 Michael Catanzaro 2015-07-13 18:36:49 UTC
> Can I throw an exception for " < 0" case 

Exceptions in Vala are useful for situations where you want to perform some operation but aren't sure if it will succeed or not. They're not useful for programming bugs.

>     or assert on timeout > 0
> and crash the game for such erroneous situations ?

Yes, asserts work well for this. You could add a requires(engine_timeout >= 0) to the function declaration, for example.
Comment 11 Sahil Sareen 2015-07-14 09:00:29 UTC
(In reply to Michael Catanzaro from comment #10)
> Yes, asserts work well for this. You could add a requires(engine_timeout >=
> 0) to the function declaration, for example.

Awesome!!!!!

I didn't know vala supported contract programming.
Just looked it up on https://wiki.gnome.org/Projects/Vala/Tutorial
Comment 12 Sahil Sareen 2015-07-15 05:51:14 UTC
Created attachment 307447 [details] [review]
Prevent a buggy engine from living forever

Leaving for another review incase there are any more comments, 
Will push up in a day.
Comment 13 Michael Catanzaro 2015-07-15 12:46:35 UTC
Review of attachment 307447 [details] [review]:

LGTM, thanks!
Comment 14 Sahil Sareen 2015-07-15 18:58:13 UTC
Pushed to master.

To ssh://ssareen@git.gnome.org/git/gnome-chess
   ff3f644..9329b59  master -> master