Skip to content

Winrm hook, run can't be called twice #46668

Description

@darkag

Apache Airflow version

2.10.5

If "Other Airflow 2 version" selected, which one?

No response

What happened?

When using winrm hook, the following code fail

 hook = WinRMHook(ssh_conn_id="conn")
 _, stdout_buffer, _ = hook.run(command='echo test')
 _, stdout_buffer, _ = hook.run(command='echo test2')

this is due to an inconsistence between the get_conn and run functions :

  • get_conn : if clientid is not define open a new shell and store the clientid, else return the clientid
  • run : call get_conn, launch the command and close the shell but not set clientid to null, so the next call of run will try to launch command on a closed shell

What you think should happen instead?

we should be able to call run multiple times without having to create a new hook.
run should at least set clientid to null after closing shell, but I think that it would be better if get_conn doesn't open a shell since it will create a process on distant server that may never close if you forget to explicitly close it.

How to reproduce

run the above code in a task

Operating System

debian

Versions of Apache Airflow Providers

apache-airflow-providers-microsoft-winrm==3.6.1

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions