This repository has been archived by the owner on Mar 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
che-1518 Fix creation zombie prosess when user closes terminal. #11
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@evoevodin @garagatyi review please. |
if err != nil { | ||
log.Fatalf("Websocket upgrade failed: %s\n", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer conn.Close()
|
AndrienkoAleksandr
force-pushed
the
che-1518
branch
4 times, most recently
from
August 12, 2016 06:48
6653691
to
f64fa83
Compare
Ok for me, @garagatyi please take a look |
AndrienkoAleksandr
force-pushed
the
che-1518
branch
from
August 12, 2016 09:07
f64fa83
to
e29766d
Compare
LGTM |
voievodin
reviewed
Oct 20, 2016
log.Printf("Failed to stop process, due to occurred error '%s'", err.Error()) | ||
} | ||
|
||
if len(done) != 2 { |
There was a problem hiding this comment.
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()
}
}
}
voievodin
approved these changes
Oct 20, 2016
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>
AndrienkoAleksandr
force-pushed
the
che-1518
branch
from
October 21, 2016 14:22
c60ca3f
to
976c49b
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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