Repository: godot
Issue: Random repro: Godot 4: AnimatedSprite2D: Animation plays multiple times but calling animation_finished signal only once
Labels: bug,needs testing,topic:animation,topic:2d

### Godot version

4.1.2.stable.flathub [399c9dc39]

### System information

Godot v4.1.2.stable (399c9dc39) - Freedesktop SDK 23.08 (Flatpak runtime) - Wayland - Vulkan (Compatibility) - Mesa Intel(R) Xe Graphics (TGL GT2) () - 11th Gen Intel(R) Core(TM) i5-11320H @ 3.20GHz (8 Threads)

### Issue description

I find Godot 4 AnimatedSprite2D can repeatedly play an animation more than once, then calls animation_finished handler function once. It can be demonstrated with the following code sample below. A summary of how to trigger it:

1. $AnimatedSprite2D.play() is called in _process().
2. The nimation name (a variable) is changed outside _process().
3. I use animation_finished to capture the end of animation playback.

A set of gif files are attached below to compare the results. They are from same code but different runs. Note that the issue is not stably reproduced. When I got bug report, I ran 29 times, and got 5 case flashing twice, and 2 extemely wrong case that flashes 5 times.

Please pay attention to the flashes of gold (once vs multiple times) and printed message "STATUS_COLLECTED animation played ...". The message always play once.

The same behavior is identified on both Linux and macOS.

### Good case demo - Animation is played only once.
![2023-10-31 22-08-23](https://github.com/godotengine/godot/assets/183941/75a704fd-bc47-43cb-9ef1-23da2915ad4f)

### Wrong case demo - Animation is played twice
![2023-10-31 22-12-23](https://github.com/godotengine/godot/assets/183941/959ea1f4-b221-4890-a631-623cb8207329)

### Extremely wrong case demo - Animation is played multiple times.
![2023-10-31 22-08-41](https://github.com/godotengine/godot/assets/183941/00da4684-ce8b-4594-bcb2-18c59b62f947)



### A simplified code sample
```
func _process(delta: float) -> void:
    $AnimatedSprite2D.play(animation[action_status])

func _on_self_destroy_timer_timeout() -> void:
    action_status = STATUS_COLLECTED  # Wait for 3 seconds to trigger animation change (static -> flash)

func _on_animated_sprite_2d_animation_finished() -> void:
    if action_status == STATUS_COLLECTED:
        print("STATUS_COLLECTED animation played once - can't be guranteed")
        queue_free() # Call queue_free() when animation is finished.
```


### Context

This issue is reported during the same migration project with godotengine/godot-docs#8372 from Godot 3 to 4. An experiment shows, that Godot 3 can guarantee to play STATUS_COLLECTED animation once and then call animation_finished handler once, but Godot 4 does not guarantee this: it can play animation multiple times, then call animation_finished handler once. Again, it seems an inconsistency between Godot 3 and Godot 4.

Impact to player: Test players felt confused because they thought the repeated animation some different/special kind of gold, so they raised a question to me that whether this is a speical update in game.

### Steps to reproduce

1. Checkout project https://github.com/fuzhouch/godot-3to4-comparison/ to local, say ./godot-3to4-comparison.
2. Launch Godot 4.1.2. Open godot 4 project, ./godot-3to4-comparison/godot4/project.godot
3. From Godot 4 editor, Launch scene, [demo_animation_sprite_2d_play_animation_bad.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animation_sprite_2d_play_animation_bad.tscn)

NOTE: The project is kinds of as minimal as possible. It contains multiple scenes, while each of which are presenting a single bug. Every scene is self-contained, and do not depends on each other.

The scene uses a 3-second timer to tigger problematic animation. So open the scene, wait for 3 seconds, then we can see the gold flashes and disappears. 

Result: 
- In good case, It should flash only once, but it randomly flashes multiple times.
- No matter it flashes once or multiple times, the animation_finished signal handler is called once. As expected. (Proof: the print() message is written to debug window only once) 

A workaround:

Simplify move $AnimatedSprite.play() out from _process(), but call it in different signal callbacks.

As a comparison of Godot 3, use step below:

1. Launch Godot 3.5.3, then open Godot 3 project, ./godot-3to4-comparison/godot3/project.godot
2. From Godot 3 editor, Launch scene, [Demo_AnimatedSprite2D_Play_Animation.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot3/Demo_AnimatedSprite2D_Play_Animation.tscn) 

In my experiment, Godot 3.5.3, the gold always flashes once, then animation_finished handler is called once. The same code also works on my production game.

### Minimal reproduction project

- Project repository: https://github.com/fuzhouch/godot-3to4-comparison/
- Godot 4 project path (for reproducing issue): godot4/
- Godot 3 project path (for behavior comparison): godot3/

- The scene we use to reproduce the bug: [demo_animation_sprite_2d_play_animation_bad.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animation_sprite_2d_play_animation_bad.tscn)
- The scene that shows workaround: [demo_animation_sprite_2d_play_animation_good.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot4/demo_animation_sprite_2d_play_animation_good.tscn)
- The scene (under project godot3, requires Godot 3.5.3) for behavior comparison: [Demo_AnimatedSprite2D_Play_Animation.tscn](https://github.com/fuzhouch/godot-3to4-comparison/blob/main/godot3/Demo_AnimatedSprite2D_Play_Animation.tscn)