You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As per subject, Wait() may run into a subtle deadlock if the child buffer is not drained. Consider the following example:
package main
import"github.com/ThomasRooney/gexpect"import"fmt"funcmain() {
fmt.Printf("Starting...\n")
child, err:=gexpect.Spawn("bash")
iferr!=nil {
panic(err)
}
child.Expect("$")
fmt.Printf("Got prompt..\n")
len:=8000child.SendLine(fmt.Sprintf("for i in `seq %d`; do echo 'a'; done", len))
child.SendLine(`exit`)
fmt.Printf("Waiting for exit...\n")
child.Wait()
fmt.Printf("Done\n")
child.Close()
}
When running this, Wait() will never return. Lowering the len value, it will correctly return.
The problem with the example is that child output should be asynchronously drained while waiting, otherwise it can block when writing to the pty and deadlock with the parent (gexpect) as shown in strace:
As per subject,
Wait()
may run into a subtle deadlock if the child buffer is not drained. Consider the following example:When running this,
Wait()
will never return. Lowering thelen
value, it will correctly return.The problem with the example is that child output should be asynchronously drained while waiting, otherwise it can block when writing to the pty and deadlock with the parent (gexpect) as shown in strace:
This seems to be an intrinsic limitation of
Wait()
, and should be properly documented similarly to https://pexpect.readthedocs.io/en/stable/api/pexpect.html#pexpect.spawn.waitThe text was updated successfully, but these errors were encountered: