Skip to content
This repository has been archived by the owner on Mar 23, 2022. It is now read-only.

che-1518 Fix creation zombie prosess when user closes terminal. #11

Merged
merged 1 commit into from
Oct 21, 2016

Conversation

AndrienkoAleksandr
Copy link
Contributor

Fix creation zombie processes when user closes terminal by close button or prints command exit in the terminal without launched another processes.

Signed-off-by: Aleksandr Andrienko aandrienko@codenvy.com

@AndrienkoAleksandr
Copy link
Contributor Author

@evoevodin @garagatyi review please.

if err != nil {
log.Fatalf("Websocket upgrade failed: %s\n", err)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer conn.Close()

@voievodin
Copy link

go fmt file

@AndrienkoAleksandr AndrienkoAleksandr force-pushed the che-1518 branch 4 times, most recently from 6653691 to f64fa83 Compare August 12, 2016 06:48
@voievodin
Copy link

Ok for me, @garagatyi please take a look

@garagatyi
Copy link

LGTM

log.Printf("Failed to stop process, due to occurred error '%s'", err.Error())
}

if len(done) != 2 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the next concept:

type onceCloser struct {
    sync.Mutex
    waitGroup *sync.WaitGroup
    isDone    bool
    close     func()
}

func (wc *onceCloser) done() {
    defer wc.Unlock()
    wc.Lock()
    if wc.isDone {
        wc.isDone = true
        wc.close()
        wc.waitGroup.Done()
    }
}

then you can create 2 closers for connection and pty file:

    wg := &sync.WaitGroup{}
    fileCloser := &onceCloser{waitGroup: wg, close: func() { closeReader(reader, wp.PtyFile) }}
    connCloser := &onceCloser{waitGroup: wg, close: func() { conn.Close() }}

and pass those closers to methods that redirect data

    //read output from terminal
    go sendPtyOutputToConnection(conn, reader, connCloser)
    //write input to terminal
    go sendConnectionInputToPty(conn, reader, wp.PtyFile, fileCloser)

and obviously inside those method do defer closer.done()

after the process is finished wp.Cmd.Wait() returned use

waitAndClose(time.Second * 5, wg, fileCloser, connCloser)

which is

func waitAndClose(howLong time.Duration, wg *sync.WaitGroup, closers ...*onceCloser) {
    c := make(chan bool)
    go func() {
        defer close(c)
        wg.Wait()
    }()
    select {
    case <-c:
    case <- time.After(howLong):
        for _, closer := range closers {
            closer.done()
        }
    }
}

@AndrienkoAleksandr AndrienkoAleksandr changed the title [WIP] che-1518 Fix creation zombie prosess when user closes terminal. che-1518 Fix creation zombie prosess when user closes terminal. Oct 21, 2016
Fix creation zombie processes when user closes terminal by close button or prints command exit in the terminal.

Signed-off-by: Aleksandr Andrienko <aandrienko@codenvy.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants