Skip to content

win_updates - reset the connection and retry the poll and cancel on any connection error - #971

Open
nbttmbrg wants to merge 2 commits into
ansible-collections:mainfrom
nbttmbrg:fix/win-updates-poll-transport-loss
Open

nbttmbrg wants to merge 2 commits into
ansible-collections:mainfrom
nbttmbrg:fix/win-updates-poll-transport-loss

Conversation

@nbttmbrg

@nbttmbrg nbttmbrg commented Nov 23, 2026 •

Copy link
Copy Markdown
SUMMARY

Fixes #970
Fixes #668

#668 looks like the same root cause (connection lost while installing a network driver or a cumulative update), but the network driver case was not reproduced.

The update task started by win_updates runs outside of the WinRM shell, and its pipe server accepts a new client, so losing the connection while polling is recoverable. Today the poll is retried once, on the same connection, and only for AnsibleConnectionFailure and requests timeouts, and the cancel is not retried. The psrp and winrm connection plugins raise some connection errors as is, e.g. a WSManFaultError when the shell is aborted, and winrm keeps using the same shell. The task then fails, the cancel is sent on the same broken connection and fails too, and the update task keeps running on the host.

  • Retry any error raised while polling or cancelling, like plugin_utils/_reboot.py already does, with the same capped exponential backoff, up to 5 retries. The cancel can safely be sent more than once.
  • Reset the connection before each retry so the command runs on a new shell.

The warnings and the returned values are unchanged.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

win_updates

ADDITIONAL INFORMATION
  • Unit tests: new test_wsman_fault_during_poll and test_wsman_fault_during_cancel (raw exception, the run completes after a reset), test_multiple_connection_failures_during_poll updated for the retry counts. All three fail on main.
  • Reproduced and verified on Windows Server 2022 over psrp and winrm, by killing the shell host (wsmprovhost.exe / winrshost.exe) and by restarting WinRM while polling: all four now succeed. Each logs Connection failure when polling update result - attempting to retry: ... (WSMan fault 1726/995 over psrp, InvalidSelectors over winrm) or, when the shell dies after the last poll, Connection failure when cancelling update task - attempting to retry: Access is denied. .... Each then reconnects, gets the final result and cancels the update task, which exits cleanly with no pipe or process left on the host. While WinRM was restarting, one psrp retry also failed with invalid literal for int() with base 10: '' raised from the psrp stack. That is why any error is retried rather than a list of exception types.
  • win_updates integration target run against the same host over psrp and winrm (ansible-test windows-integration win_updates --inventory ..., Server 2022): passed.

No integration test is added for the connection loss itself: breaking the shell inside the poll window is not deterministic on the CI hosts.

🤖 Generated with Claude Code

Edit : IDK what your stance is on AI Assisted coding, I just want to stress out that this was not 100% coded with Claude and heavily re-read and supervised. Not being an english native, I was lazy enough to let it write the whole issue text though, hope it's OK and not too robotic for you. Happy to correct anything :)

nbttmbrg and others added 2 commits November 23, 2026 11:29
The update task started by win_updates runs outside of the WinRM shell
and its pipe server accepts a new client, so losing the connection while
polling is recoverable. The poll was only retried once, on the same
connection, and only for AnsibleConnectionFailure and requests timeouts,
and the cancel was not retried. The psrp and winrm connection plugins
raise some connection errors as is, e.g. a WSManFault when the shell is
aborted, and winrm keeps using the same shell. The task then failed, the
cancel failed on the same broken connection, and the update task kept
running on the host with nobody tracking it.

Retry any error raised while polling or cancelling, like
plugin_utils/_reboot.py does, with the same capped exponential backoff,
and reset the connection before each retry so the command runs on a new
shell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fix the yaml[line-length] lint failure and mention the cancel retry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nbttmbrg

Copy link
Copy Markdown
Author

The Ansible devel Units failure is not related to this change: tests/unit/conftest.py fails to import before any test runs.

tests/unit/conftest.py:9: in <module>
    from ansible.utils.collection_loader._collection_finder import _AnsibleCollectionFinder
E   ModuleNotFoundError: No module named 'ansible.utils.collection_loader._collection_finder'; 'ansible.utils.collection_loader' is not a package

ansible-core devel moved the collection loader to ansible.module_utils._internal._collection_loader in ansible/ansible#87835 (ansible/utils/collection_loader is now a module, not a package). The devel Units job of previous PRs ran before that change, and this PR is the first one since that runs controller unit tests.

The Ansible 2.22 Lint failure was the changelog fragment line length, fixed in the last commit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant