Sign in to follow this  
Friya

Server hanging (aka Waiting for Steam authentication...)

Recommended Posts

I've been chasing a bug in Wurm for a little while now.

 

To a client it reveals itself like this when you try to log in: "Waiting for Steam authentication...", and it will hang there. There are probably situations where you see that message and it actually is true, but in the case of this bug it's just an unfortunate side-effect.

 

The server is most likely hanging in a deadlock or an infinite loop. It will not accept any new connections and all connected clients will eventually disconnect due to timeouts.

 

What you will see in the server log are some threads chugging along doing some work (outputting statistics and such), making it seem like it's kind of working. In the case I was asked to help track down, it was not, the mainthread is frozen (deadlocked/infinite loop). You have to restart your server in order to get things going again.

 

So, off I went to find out where... and it SEEMS I have found it, but I'd like a few more eyeballs on it before I call it a day and pat myself on the back.

 

It lies in the movement code of creatures and it's called from a bunch of different places. This code was introduced somewhere between 1.4 and 1.6 (I was out of
the loop so don't have source for all version). It probably all came with the introduction of the "Creature Movement Changes" feature.

 

In Creature.takeSimpleStep() we have:

    ... a little code ...
    for (int x = 0; x < mvs; ++x) {
        ... lots of code ...
        if ((lDiffTileX != 0 || lDiffTileY != 0) && !this.isGhost()) {
            ... even more code ...
            if (Features.Feature.CREATURE_MOVEMENT_CHANGES.isEnabled()) {
                this.turnTowardsTile((short)this.getTileX(), (short)this.getTileY());
                this.rotateRandom(this.status.getRotation(), 45);
                x = 0;
                this.getStatus().setMoving(false);
                continue;
            }
            ... some code ...
        }
        ... even more code ...
    }
    ... even more code ...

Setting x to 0 in the iteration here ... is potentially lethal.

 

I am curious if anyone with access to the original source code (or author of the code) can shed some light on the intended behaviour and/or state that this can never cause an infinite loop due to the conditions set by:

    this.turnTowardsTile((short)this.getTileX(), (short)this.getTileY());
    this.rotateRandom(this.status.getRotation(), 45);
    this.getStatus().setMoving(false);

I have a hard time wrapping my head around the scenarios and the intentions (hence request for more eyeballs). That said even if it is guaranteed that we will not reset x every iteration, I have to say that this is also terribly nasty programming. ?

 

If this is indeed causing spurious errors on your server a work-around for now:
Disable the server feature "Creature Movement Changes" and it should fix the problem until a real patch can be released (since I don't know the intentions of this, I will not release a patch myself).

 

But first and foremost, would like to hear some feedback on this as I have simply run out of patience waiting for the bug to manifest itself on a live server (it's rare enough).
 

TLDR:
    for (int x = 0; x < mvs; ++x) {
        if(condition) {
            x = 0;
            continue;
        }
    }
    // we might never get here.

 

  • Like 2

Share this post


Link to post
Share on other sites

Hmm that piece of code is reached when 1) a creature is moving across a tile border 2) there is something blocking the move 3) the creature is not a guard and 4) new movement is enabled

 

Also when that code is reached it is rotated in a random direction, so in most cases i guess the next iteration will not hit that blocker and the loop will sooner or later end.

 

If a creature is enclosed in a 1x1 pen and is fast enough to always move more than one tile in a single tick it will keep hitting that regardless of random rotations and will go into an endless loop.

 

But... i don't see any creatures fast enough for that in vanilla. Even a champion sea serpent would move at 2.8 meters per tick guaranteeing that after a few rotations it would end up with a move that's within the same tile and break out of the loop. 

 

Are people seeing that hang running modded creatures that are significantly faster?

Share this post


Link to post
Share on other sites

It's funny that you mention it, was just sitting here talking to someone saying that it would only be at a certain speed. So it might only be happening in combination with mods. But yes, definitely -- mods affecting movement speed all over the place.

 

The creature I have seen causing this is not in a 1x1, but I have been betting on it being in a corner of the enclosure.

 

Thanks for taking a look, it does confirm that I'm not barking up the wrong tree. :)

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this