Giter Club home page Giter Club logo

posix-pty's People

Contributors

merijn avatar andygill avatar spwhitton avatar thomasjm avatar

Stargazers

 avatar dsl avatar Patrick Cieplak avatar Tung Dao avatar Daisuke Fujimura avatar  avatar winterland avatar Daniel Kahlenberg avatar Dave Della Costa avatar

Watchers

 avatar James Cloos avatar  avatar

posix-pty's Issues

Forking can interact with runtime to cause livelock (100% cpu usage) or freezing

If spawnWithPty is called at an unlucky time (i.e. when other system calls like printing to stderr and launching other processes are happening) then some kind of bad interaction with the runtime can get triggered, resulting in either full CPU livelock (stuck at 100% across all CPUs) or freezing of the Haskell process.

A nice repro (courtesy of u/Noughtmare on Reddit) is below. You can also find my original, slightly more complicated version as a full repo here.

module Main where

import Control.Concurrent
import Control.Monad
import System.Posix.Pty
import System.Process

main :: IO ()
main = do
  forkIO $ replicateM_ 1000 $ putStrLn "This is a test"

  -- Repeat this 20 times
  replicateM_ 20 $ do
    forkIO $ void $ spawnWithPty Nothing True "sleep" ["99999999"] (80, 24)
    forkIO $ void $ readCreateProcess (proc "echo" ["hi"]) ""

  -- All CPUs should now be stuck at 100%
  threadDelay 60000000

I'm filing this issue after a Reddit discussion which determined that posix-pty most likely needs to be more careful about how it forks. You can see the discussion here: https://www.reddit.com/r/haskell/comments/d4h7ty/why_does_this_code_livelock_all_my_cpus_at_100/

Lost bytes of output due to GHC buffering

While using pty-wrap on output of tools like nix-instantiate, hGetSome encounters GHC.IO buffering and tryReadPty assumes the protocol that relies on using read() directly.

The fix to this has been included to #5 that has been left ignored for a while.

control-d issue

I'm using posix-pty to write a program that is similar to the script command, that runs bash in a pty and forwards input and output between it and the user's terminal. For some reason, control-d is not being handled in the usual way. Usually, when at the bash prompt and nothing has been typed, control-d will be caught by bash and it runs "exit". Using posix-pty, instead "^D" gets displayed, and bash does not exit.

My program was earlier not using posix-pty and was setting up the pty itself and running a program connected to it using System.Process. In that version, control-d worked as expected.

My program is reading "\EOT" from the user, and is feeding that into writePty.

I suspect that something about how posix-pty sets up the pty is causing the problem. Perhaps something in fork_exec_with_pty?

You can find the two versions of my program here:

add a way of closing a Pty

Right now, if you call spawnWithPty too many times (~128), the commands fails, even if the process being created for each Pty has terminated.

Perhaps a ptyClose would help here, but generally some way of returning the Pty UNIX resource.

ptyClose :: Pty -> IO ()

The package I am working on is https://github.com/andygill/plist-buddy, a wrapper around the OSX plist-buddy command, and the quickcheck tests are failing because of this.

Test suite failure

Thank you for this library!

The test suite does not pass. Is this a known issue, or is there a bug?

iris ~/tmp % cabal get posix-pty
Unpacking to posix-pty-0.2.1.1/
iris ~/tmp % cd posix-pty-0.2.1.1 
iris ~/tmp/posix-pty-0.2.1.1 % cabal sandbox init
Writing a default package environment file to
/home/spwhitton/tmp/posix-pty-0.2.1.1/cabal.sandbox.config
Creating a new sandbox at /home/spwhitton/tmp/posix-pty-0.2.1.1/.cabal-sandbox
iris ~/tmp/posix-pty-0.2.1.1 % cabal test        
Package has never been configured. Configuring with default flags. If this
fails, please run configure manually.
Resolving dependencies...
Configuring posix-pty-0.2.1.1...
Preprocessing library posix-pty-0.2.1.1...
[1 of 1] Compiling System.Posix.Pty ( System/Posix/Pty.hs, dist/build/System/Posix/Pty.o )

In file included from /usr/include/x86_64-linux-gnu/sys/ioctl.h:21:0: error:
    0,
                     from cbits/fork_exec_with_pty.c:2:

/usr/include/features.h:148:3: error:
     warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
     # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
       ^~~~~~~

In file included from /usr/include/x86_64-linux-gnu/sys/ioctl.h:21:0: error:
    0,
                     from cbits/fork_exec_with_pty.c:2:

/usr/include/features.h:148:3: error:
     warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
     # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
       ^~~~~~~
Preprocessing test suite 'stty' for posix-pty-0.2.1.1...
[1 of 1] Compiling Main             ( tests/stty.hs, dist/build/stty/stty-tmp/Main.o )
Linking dist/build/stty/stty ...
Running 1 test suites...
Test suite stty: RUNNING...
speed 38400 baud;
rows 10; columns 10;
line = 0;
intr = ^C;
quit = ^\;
erase = ^?;
kill = ^U;
eof = ^D;
eol = <undef>;
eol2 = <undef>;
swtch = <undef>;
start = ^Q;
stop = ^S;

susp = ^Z;
rprnt = ^R;
werase = ^W;
lnext = ^V;
discard = ^O;
min = 1; time = 0;
-parenb
-parodd
-cmspar cs8
-hupcl
-cstopb
cread
-clocal

-crtscts

-ignbrk

-brkint

-ignpar

-parmrk

-inpck

-istrip
-inlcr

-igncr
icrnl ixon
-ixoff
-iuclc

-ixany
-imaxbel
-iutf8

opost
-olcuc
-ocrnl

onlcr
-onocr

-onlret

-ofill

-ofdel nl0

cr0 tab0
bs0 vt0 ff0

isig icanon
iexten echo

echoe echok
-echonl
-noflsh
-xcase

-tostop
-echoprt

echoctl
echoke

-flusho
-extproc

stty: fdReadBuf: hardware fault (Input/output error)
Test suite stty: FAIL
Test suite logged to: dist/test/posix-pty-0.2.1.1-stty.log
0 of 1 test suites (0 of 1 test cases) passed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.