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

Darwin: Freezes if not reading stdout. #101

Closed
Mattemagikern opened this issue Jul 18, 2020 · 4 comments
Closed

Darwin: Freezes if not reading stdout. #101

Mattemagikern opened this issue Jul 18, 2020 · 4 comments

Comments

@Mattemagikern
Copy link

Hello!

I've found a difference in behaviour between Mac and Linux using your module.

package main

import (
	"github.com/creack/pty"

	"os/exec"
	"testing"
)

func TestCommand(t *testing.T) {
	c := exec.Command("./echo.sh", "TestCommand")
	pty, err := pty.Start(c)
	if err != nil {
		t.Fatal(err)
	}
	defer pty.Close()
	err = c.Wait()
	if err != nil {
		t.Fatal(err)
	}
}

echo.sh:

#!/bin/bash
echo $@

If this is run on linux it will pass, on darwin it will freeze.
However If I add a buffer to c.stdout it will pass.
My guess is that the master file descriptor isn't buffering output from the slave. Which is really strange.
On the otherhand if you replace ./echo.sh to echo it will pass.

I'm not sure what I'm seeing or how to amend it.
My guess is a combination between differences in the os/exec between linux and darwin and file settings differences between darwin and linux regarding the master terminal.

Do you have any idea what this might be?

Best regargs,
Måns Ansgariusson

Go version: 1.14
pty version: v1.1.11

@creack
Copy link
Owner

creack commented Jul 30, 2020

I am sorry, I didn't have time to look into this just yet. Will do asap, I should have time over the weekend.

@Mattemagikern
Copy link
Author

No stress :)

@creack
Copy link
Owner

creack commented Aug 4, 2020

I managed to reproduce.

To be honest, I am not 100% sure of the reason.

Adding a sink instead of a buffer is probably better (go io.Copy(ioutil.Discard, pty)).

I think you are right and it as to do with some lower-level difference on how the tty driver works between linux and darwin.

That being said, it looks quite specific to bash. if you switch to zsh, it doesn't block.

Do you have a specific use-case where is could cause concern? From the looks of it, I'd be inclined to simply close this as a non-issue.
As a rule of thumb, even in tty mode, when the process writes, something should read it.

@Mattemagikern
Copy link
Author

Sweet!

Adding a sink instead of a buffer is probably better (go io.Copy(ioutil.Discard, pty)).

This solved it for me as well.

That being said, it looks quite specific to bash. if you switch to zsh, it doesn't block.

That is super interesting! I'll defenetly dig into that, didn't think of testing another shell.

Do you have a specific use-case where is could cause concern? From the looks of it, I'd be inclined to simply close this as a non-issue.
As a rule of thumb, even in tty mode, when the process writes, something should read it.

Yes, close it. I agree that it is expected that something should read what is outputed from the pty.
I was making test-cases for a project of mine when i stumbled upon this.

Thank you for your time debugging this :)

Best regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants