Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many ssh <defunct> then using library. #139

Closed
neodiz opened this issue Feb 29, 2024 · 5 comments
Closed

Many ssh <defunct> then using library. #139

neodiz opened this issue Feb 29, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation v2.0.0

Comments

@neodiz
Copy link

neodiz commented Feb 29, 2024

Good afternoon. I think I found a problem in the library, a large number of child processes are not closed. Here is my example

`func ansible() error {
fmt.Println("test")
ansiblePlaybookConnectionOptions := &options.AnsibleConnectionOptions{
User: "inurmuhametov",
SSHExtraArgs: "-o ControlPersist=360s",
SCPExtraArgs: "-o ControlPersist=360s",
SFTPExtraArgs: "-o ControlPersist=360s",
}

ansiblePlaybookOptions := &playbook.AnsiblePlaybookOptions{
	Inventory:  "<server>,",
	VerboseVVVV:true,
}

playbook := &playbook.AnsiblePlaybookCmd{
	Playbooks:         []string{
		"/tmp/performance.yml"},
	ConnectionOptions: ansiblePlaybookConnectionOptions,
	Options:           ansiblePlaybookOptions,
}

err := playbook.Run(context.TODO())
if err !=nil {
	playbook = nil
	return err
}
playbook = nil
return nil

}
func main() {

for ; ;  {
	ansible()
	time.Sleep(5 * time.Minute)
}

}`

`
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 1229188 6164 pts/0 Ssl+ 12:13 0:00 /app
root 17 0.0 0.0 0 0 ? Zs 12:13 0:00 [ssh]
root 18 0.0 0.0 0 0 ? Zs 12:13 0:00 [ssh]
root 64 0.0 0.0 7636 4192 pts/1 Ss 12:14 0:00 bash
root 102 0.0 0.0 0 0 ? Zs 12:18 0:00 [ssh]
root 103 0.0 0.0 0 0 ? Zs 12:18 0:00 [ssh]
root 393 0.0 0.0 0 0 ? Zs 12:23 0:00 [ssh]
root 394 0.0 0.0 0 0 ? Zs 12:23 0:00 [ssh]
root 437 0.0 0.0 0 0 ? Zs 12:29 0:00 [ssh]
root 438 0.0 0.0 0 0 ? Zs 12:29 0:00 [ssh]
root 481 0.0 0.0 0 0 ? Zs 12:34 0:00 [ssh]
root 482 0.0 0.0 0 0 ? Zs 12:34 0:00 [ssh]
root 525 0.0 0.0 0 0 ? Zs 12:39 0:00 [ssh]
root 526 0.0 0.0 0 0 ? Zs 12:39 0:00 [ssh]
root 569 0.0 0.0 0 0 ? Zs 12:44 0:00 [ssh]
root 570 0.0 0.0 0 0 ? Zs 12:44 0:00 [ssh]
root 613 0.0 0.0 0 0 ? Zs 12:49 0:00 [ssh]
root 614 0.0 0.0 0 0 ? Zs 12:49 0:00 [ssh]
root 657 0.0 0.0 0 0 ? Zs 12:54 0:00 [ssh]
root 658 0.0 0.0 0 0 ? Zs 12:54 0:00 [ssh]
root 701 0.0 0.0 0 0 ? Zs 12:59 0:00 [ssh]
root 702 0.0 0.0 0 0 ? Zs 12:59 0:00 [ssh]
root 745 0.0 0.0 0 0 ? Zs 13:05 0:00 [ssh]
root 746 0.0 0.0 0 0 ? Zs 13:05 0:00 [ssh]
root 789 0.0 0.0 0 0 ? Zs 13:10 0:00 [ssh]
root 790 0.0 0.0 0 0 ? Zs 13:10 0:00 [ssh]
root 833 0.0 0.0 0 0 ? Zs 13:15 0:00 [ssh]
root 834 0.0 0.0 0 0 ? Zs 13:15 0:00 [ssh]
root 877 0.0 0.0 0 0 ? Zs 13:20 0:00 [ssh]
root 878 0.0 0.0 0 0 ? Zs 13:20 0:00 [ssh]
root 921 0.0 0.0 0 0 ? Zs 13:25 0:00 [ssh]
root 922 0.0 0.0 0 0 ? Zs 13:25 0:00 [ssh]
root 965 0.0 0.0 0 0 ? Zs 13:30 0:00 [ssh]
root 966 0.0 0.0 0 0 ? Zs 13:30 0:00 [ssh]
root 1009 0.0 0.0 0 0 ? Zs 13:35 0:00 [ssh]
root 1010 0.0 0.0 0 0 ? Zs 13:35 0:00 [ssh]
root 1053 0.0 0.0 0 0 ? Zs 13:41 0:00 [ssh]
root 1054 0.0 0.0 0 0 ? Zs 13:41 0:00 [ssh]
root 1097 0.0 0.0 0 0 ? Zs 13:46 0:00 [ssh]
root 1098 0.0 0.0 0 0 ? Zs 13:46 0:00 [ssh]
root 1141 0.0 0.0 0 0 ? Zs 13:51 0:00 [ssh]
root 1142 0.0 0.0 0 0 ? Zs 13:51 0:00 [ssh]
root 1185 0.0 0.0 0 0 ? Zs 13:56 0:00 [ssh]
root 1186 0.0 0.0 0 0 ? Zs 13:56 0:00 [ssh]
root 1229 0.0 0.0 0 0 ? Zs 14:01 0:00 [ssh]
root 1230 0.0 0.0 0 0 ? Zs 14:01 0:00 [ssh]
root 1273 0.0 0.0 0 0 ? Zs 14:06 0:00 [ssh]
root 1274 0.0 0.0 0 0 ? Zs 14:06 0:00 [ssh]
root 1317 0.0 0.0 0 0 ? Zs 14:11 0:00 [ssh]
root 1318 0.0 0.0 0 0 ? Zs 14:11 0:00 [ssh]
root 1361 0.0 0.0 0 0 ? Zs 14:16 0:00 [ssh]
root 1362 0.1 0.0 0 0 ? Zs 14:16 0:00 [ssh]

`

@apenella
Copy link
Owner

apenella commented Mar 4, 2024

Hi @neodiz!
Thank you very much for raising that issue. I will take a look at this.
Just letting you know, I will work on fixing that over the v2.0.0. By the way, have you tried setting a cancel context instead of the TODO one?

I keep you updated!

@apenella apenella added bug Something isn't working v2.0.0 and removed Pending Analysis labels Mar 16, 2024
@apenella
Copy link
Owner

Hi @neodiz!
I could reproduce what you experienced, which allowed me to work on a solution to that issue. Unfortunately, I don't have a fix for that yet.
My first thought was that the go-ansible code did not manage properly the processes spawned by the process started by the library. I tried to set up the SysProcAttr or create a process group to handle the child processes but any of those was a deterministic solution.

I have realized that when I executed the ansible-playbook it also left some SSH zombie processes, and that allowed me to explore new avenues.
The cause of my problem was that I executed the playbook inside a container without the init enabled (read here), so no one reaped zombie processes.

Please, can you provide me with the following information?

  • Are you running Ansible within a container?
  • As is said here, Ansible sets the SSH -tt parameter and that could leave zombie process on your system, coming from the pseudo-tty. That parameter should be overwritten by adding the -T on the SSH extra arguments. Can you confirm if you still have zombie processes after setting the -T parameter?

Thank you very much!

@neodiz
Copy link
Author

neodiz commented Mar 19, 2024 via email

@apenella apenella removed bug Something isn't working v2.0.0 labels Mar 20, 2024
@apenella
Copy link
Owner

Hi @neodiz!
I understand that the issue has been solved and I could close the issue.
I will follow your recommendation and I will include a section in the documentation explaining that behaviour and how to solve this.

Thank you very much!

@apenella apenella added v2.0.0 Enhancement documentation Improvements or additions to documentation and removed Enhancement labels Apr 2, 2024
@apenella
Copy link
Owner

apenella commented Apr 4, 2024

Available in v2.0.0-rc-3

@apenella apenella closed this as completed Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation v2.0.0
Projects
None yet
Development

No branches or pull requests

2 participants