Player Stuck on nothing

In my game I use AStar to attack enemies. These enemies also use AStar.
For my player I have this script that runs on update.

There are times when the player is just stuck with a green path still in gizmo but it will not move at all. I use a layered grid graph and this happens about 5% of the time, but it really ruins the gameplay because I use AStar for each and every player attack.

Video of bug : (happens in the middle of it )

/// <summary>
    /// Updates the path to the current pathfinding target, this runs every frame
    /// </summary>
    void UpdatePath()
        // only ai move if we have a target
        if (currentTarget == null)
            astarTravelTime = MAX_ASTAR_TRAVEL_TIME;
            ai.canMove = false;
        astarTravelTime -= Time.deltaTime;
        // we have a target
        ai.canMove = true;
        ai.destination = currentTarget.transform.position;
        if (RepathRateTimer > 0)
            RepathRateTimer -= Time.deltaTime;
            RepathRateTimer = 0.2f;
        animancer.SetFloat("InputMagnitude", 1.0f);
        RotateTowardTarget(currentTarget.transform.position, 10.0f);

        if ((ai.reachedDestination || Vector3.Distance(transform.position, ai.destination) <= 1.5))
            // start the attack

        } else if (astarTravelTime < 0)
            // failed to reach target!



Path Failed : Computation Time 0.000 ms Searched Nodes 0
Error: Canceled by script (Seeker.CancelCurrentPathRequest)
Path Number 49503 (unique id)
AstarPath:LogPathResults(Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:835)
AstarPath:<InitializePathProcessor>b__122_1(Path) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1297)
Pathfinding.PathProcessor:CalculatePathsThreaded(PathHandler) (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:379)
Pathfinding.<>c__DisplayClass24_0:<.ctor>b__0() (at Assets/AstarPathfindingProject/Core/Misc/PathProcessor.cs:110)


The warning indicates that the path was prematurely cancelled.
This is due to your script. It will call ai.SearchPath using a timer that doesn’t care if the agent is currently calculating a path or not. I would recommend that you check ai.pathPending first.
Note that the ai already has a built-in path recalculation timer controlled by the repathRate field. Is there a reason you are not using that?