GitHub | Documentation | Become a Patron

Avoid server crash with try catch?



  • Hello,

    There are times when my game server crashes because of an exception thrown in a single game room. I want to avoid this behaviour by exception handling. However, I don't know where I should put my try catch block to handle all the errors thrown in a single game room instance.

    Any ideas?


  • administrators

    Hi @halilbilgin, which error are you seeing, and during which callback? (onJoin, onMessage, onLeave?)

    Do you have a stack trace?

    It makes sense avoiding a total server crash, but the error messages should be still easy to catch somehow during development.

    Cheers



  • The way I see it, the kind of server errors you will get in a try/catch actually mean that you have something wrong in your game code, like a use-case you are not contemplating or a parameter you are not validating properly maybe.
    Of course you can also run out of memory, CPU power or some issue like that which could be not related directly related to the case but for that you can always monitor the resources consumption and make sure you server maintenance is the proper for the expected traffic.
    I would recommend to debug everything properly and run some stress tests to make sure that you are not missing anything.
    Best,



  • Thanks for answers and recommendations. My aim was to avoid crashs due to the bugs I haven't discovered yet, or any undefined action client made that could make the whole server(all the other rooms) crash.

    As an answer to @endel, errors that I have come across so far was thrown from timeout callback functions so putting try catch to onJoin might not help :) .