mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
win-async: fix race condition in async run (#43691)
This commit is contained in:
parent
08e8d8c1d5
commit
22b921d47f
3 changed files with 31 additions and 38 deletions
|
@ -1124,6 +1124,15 @@ $ErrorActionPreference = "Stop"
|
|||
# return asyncresult to controller
|
||||
|
||||
$exec_wrapper = {
|
||||
# help to debug any errors in the exec_wrapper or async_watchdog by generating
|
||||
# an error log in case of a terminating error
|
||||
trap {
|
||||
$log_path = "$($env:TEMP)\async-exec-wrapper-$(Get-Date -Format "yyyy-MM-ddTHH-mm-ss.ffffZ")-error.txt"
|
||||
$error_msg = "Error while running the async exec wrapper`r`n$_`r`n$($_.ScriptStackTrace)"
|
||||
Set-Content -Path $log_path -Value $error_msg
|
||||
throw $_
|
||||
}
|
||||
|
||||
&chcp.com 65001 > $null
|
||||
$DebugPreference = "Continue"
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
@ -1201,9 +1210,6 @@ $exec_wrapper = {
|
|||
Function Run($payload) {
|
||||
$remote_tmp = $payload["module_args"]["_ansible_remote_tmp"]
|
||||
$remote_tmp = [System.Environment]::ExpandEnvironmentVariables($remote_tmp)
|
||||
if ($null -eq $remote_tmp) {
|
||||
$remote_tmp = $original_tmp
|
||||
}
|
||||
|
||||
# calculate the result path so we can include it in the worker payload
|
||||
$jid = $payload.async_jid
|
||||
|
@ -1267,6 +1273,19 @@ Function Run($payload) {
|
|||
}
|
||||
$watchdog_pid = $process.ProcessId
|
||||
|
||||
# populate initial results before we send the async data to avoid result race
|
||||
$result = @{
|
||||
started = 1;
|
||||
finished = 0;
|
||||
results_file = $results_path;
|
||||
ansible_job_id = $local_jid;
|
||||
_ansible_suppress_tmpdir_delete = $true;
|
||||
ansible_async_watchdog_pid = $watchdog_pid
|
||||
}
|
||||
|
||||
$result_json = ConvertTo-Json $result
|
||||
Set-Content $results_path -Value $result_json
|
||||
|
||||
# wait until the client connects, throw an error if the timeout is reached
|
||||
$wait_async = $pipe.BeginWaitForConnection($null, $null)
|
||||
$wait_async.AsyncWaitHandle.WaitOne(5000) > $null
|
||||
|
@ -1283,19 +1302,6 @@ Function Run($payload) {
|
|||
$pipe.Close()
|
||||
}
|
||||
|
||||
# populate initial results before we resume the process to avoid result race
|
||||
$result = @{
|
||||
started=1;
|
||||
finished=0;
|
||||
results_file=$results_path;
|
||||
ansible_job_id=$local_jid;
|
||||
_ansible_suppress_tmpdir_delete=$true;
|
||||
ansible_async_watchdog_pid=$watchdog_pid
|
||||
}
|
||||
|
||||
$result_json = ConvertTo-Json $result
|
||||
Set-Content $results_path -Value $result_json
|
||||
|
||||
return $result_json
|
||||
}
|
||||
|
||||
|
|
|
@ -1,21 +1,8 @@
|
|||
#!powershell
|
||||
# This file is part of Ansible
|
||||
#
|
||||
# Ansible is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Ansible is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# WANT_JSON
|
||||
# POWERSHELL_COMMON
|
||||
# Copyright: (c) 2018, Ansible Project
|
||||
|
||||
#Requires -Module Ansible.ModuleUtils.Legacy
|
||||
|
||||
$parsed_args = Parse-Args $args
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
- name: async fire and forget
|
||||
async_test:
|
||||
sleep_delay_sec: 8
|
||||
sleep_delay_sec: 10
|
||||
async: 20
|
||||
poll: 0
|
||||
register: asyncresult
|
||||
|
@ -23,7 +23,7 @@
|
|||
- name: async poll immediate success
|
||||
async_test:
|
||||
sleep_delay_sec: 0
|
||||
async: 20
|
||||
async: 10
|
||||
poll: 1
|
||||
register: asyncresult
|
||||
|
||||
|
@ -61,7 +61,7 @@
|
|||
- name: async poll retry
|
||||
async_test:
|
||||
sleep_delay_sec: 5
|
||||
async: 20
|
||||
async: 10
|
||||
poll: 1
|
||||
register: asyncresult
|
||||
|
||||
|
@ -97,8 +97,8 @@
|
|||
|
||||
- name: async poll timeout
|
||||
async_test:
|
||||
sleep_delay_sec: 25
|
||||
async: 20
|
||||
sleep_delay_sec: 5
|
||||
async: 3
|
||||
poll: 1
|
||||
register: asyncresult
|
||||
ignore_errors: true
|
||||
|
@ -152,7 +152,7 @@
|
|||
|
||||
- name: echo some non ascii characters
|
||||
win_command: cmd.exe /c echo über den Fußgängerübergang gehen
|
||||
async: 20
|
||||
async: 10
|
||||
poll: 1
|
||||
register: nonascii_output
|
||||
|
||||
|
|
Loading…
Reference in a new issue