This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Process kill fix #7
Open
javruben
wants to merge
13
commits into
master
Choose a base branch
from
process-kill-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
126d343
* Added PTY support
0829ad7
* including the worker
0f62efc
* Reverted accidental change
30ce5f3
Basic deploy workflow
5555e88
do not crash chrome intentionally
nightwing 1fd048d
* Nak should run out of process * Why is findinfiles in the Find menu…
9192ac6
* Improved VFS fix * Files now open in changed state?
f213f3e
Merged from master while working on metadata
a073772
working on vfs improvements
f4dceda
Fix for processes not being terminated during disconnect
cf68f34
added the fix to consumer as well
396bbe4
Merged vfs-socket master
e1183d2
Removed console.log and commented out code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ function Worker(vfs) { | |
// Endpoints for processes at meta.process | ||
kill: kill, | ||
|
||
// Endpoints for processes at meta.pty | ||
resize: resize, | ||
|
||
// Endpoint for watchers at meta.watcher | ||
close: closeWatcher, | ||
|
||
|
@@ -47,6 +50,7 @@ function Worker(vfs) { | |
// Route other calls to the local vfs instance | ||
resolve: route("resolve"), | ||
stat: route("stat"), | ||
metadata: route("metadata"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a PR for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added it to c9/vfs-local#11 |
||
readfile: route("readfile"), | ||
readdir: route("readdir"), | ||
mkfile: route("mkfile"), | ||
|
@@ -59,6 +63,7 @@ function Worker(vfs) { | |
watch: route("watch"), | ||
connect: route("connect"), | ||
spawn: route("spawn"), | ||
pty: route("pty"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this require c9/vfs-local#11 to be merged as well ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter unless the method is called. |
||
execFile: route("execFile"), | ||
extend: route("extend"), | ||
unextend: route("unextend"), | ||
|
@@ -107,16 +112,18 @@ function Worker(vfs) { | |
err = new Error("EDISCONNECT: vfs socket disconnected"); | ||
err.code = "EDISCONNECT"; | ||
} | ||
Object.keys(streams).forEach(function (id) { | ||
var stream = streams[id]; | ||
stream.emit("close", err); | ||
}); | ||
Object.keys(proxyStreams).forEach(onClose); | ||
Object.keys(processes).forEach(function (pid) { | ||
var process = processes[pid]; | ||
console.log("PROCESS", process) | ||
process.kill(); | ||
delete processes[pid]; | ||
}); | ||
Object.keys(streams).forEach(function (id) { | ||
var stream = streams[id]; | ||
console.log("STREAM", stream) | ||
stream.emit("close", err); | ||
}); | ||
Object.keys(proxyStreams).forEach(onClose); | ||
Object.keys(watchers).forEach(function (id) { | ||
var watcher = watchers[id]; | ||
delete watchers[id]; | ||
|
@@ -163,9 +170,9 @@ function Worker(vfs) { | |
stream.pause && stream.pause(); | ||
} | ||
}); | ||
stream.on("end", function () { | ||
stream.on("end", function (chunk) { | ||
delete streams[id]; | ||
remote.onEnd(id); | ||
remote.onEnd(id, chunk); | ||
}); | ||
} | ||
stream.on("close", function () { | ||
|
@@ -178,7 +185,7 @@ function Worker(vfs) { | |
return token; | ||
} | ||
|
||
function storeProcess(process) { | ||
function storeProcess(process, onlyPid) { | ||
var pid = process.pid; | ||
processes[pid] = process; | ||
process.on("exit", function (code, signal) { | ||
|
@@ -187,22 +194,35 @@ function Worker(vfs) { | |
}); | ||
process.on("close", function () { | ||
delete processes[pid]; | ||
delete streams[process.stdout.id]; | ||
delete streams[process.stderr.id]; | ||
delete streams[process.stdin.id]; | ||
if (!onlyPid) { | ||
delete streams[process.stdout.id]; | ||
delete streams[process.stderr.id]; | ||
delete streams[process.stdin.id]; | ||
} | ||
remote.onProcessClose(pid); | ||
}); | ||
|
||
process.kill = function(code) { | ||
killtree(pid, code); | ||
}; | ||
|
||
if (onlyPid) | ||
return pid; | ||
|
||
var token = {pid: pid}; | ||
token.stdin = storeStream(process.stdin); | ||
token.stdout = storeStream(process.stdout); | ||
token.stderr = storeStream(process.stderr); | ||
return token; | ||
} | ||
|
||
function storePty(pty) { | ||
var pid = storeProcess(pty, true); | ||
var token = storeStream(pty); | ||
token.pid = pid; | ||
|
||
return token; | ||
} | ||
|
||
function killtree(pid, code) { | ||
childrenOfPid(pid, function(err, pidlist){ | ||
|
@@ -275,15 +295,15 @@ function Worker(vfs) { | |
if (!stream) return; | ||
delete streams[id]; | ||
stream.destroy(); | ||
nextStreamID = id; | ||
// nextStreamID = id; | ||
} | ||
function end(id, chunk) { | ||
var stream = streams[id]; | ||
if (!stream) return; | ||
delete streams[id]; | ||
if (chunk) stream.end(chunk); | ||
else stream.end(); | ||
nextStreamID = id; | ||
// nextStreamID = id; | ||
} | ||
|
||
function kill(pid, code) { | ||
|
@@ -292,6 +312,15 @@ function Worker(vfs) { | |
process.kill(code); | ||
} | ||
|
||
function resize(pid, cols, rows) { | ||
var process = processes[pid]; | ||
if (!process) return; | ||
|
||
// Resize can throw | ||
try { process.resize(cols, rows); } | ||
catch(e) {}; | ||
} | ||
|
||
function closeWatcher(id) { | ||
var watcher = watchers[id]; | ||
if (!watcher) return; | ||
|
@@ -323,13 +352,13 @@ function Worker(vfs) { | |
if (!stream) return; | ||
stream.emit("data", chunk); | ||
} | ||
function onEnd(id) { | ||
function onEnd(id, chunk) { | ||
var stream = proxyStreams[id]; | ||
if (!stream) return; | ||
// TODO: not delete proxy if close is going to be called later. | ||
// but somehow do delete proxy if close won't be called later. | ||
delete proxyStreams[id]; | ||
stream.emit("end"); | ||
stream.emit("end", chunk); | ||
} | ||
function onClose(id) { | ||
var stream = proxyStreams[id]; | ||
|
@@ -360,6 +389,7 @@ function Worker(vfs) { | |
switch (key) { | ||
case "stream": token.stream = storeStream(meta.stream); break; | ||
case "process": token.process = storeProcess(meta.process); break; | ||
case "pty": token.pty = storePty(meta.pty); break; | ||
case "watcher": token.watcher = storeWatcher(meta.watcher); break; | ||
case "api": token.api = storeApi(meta.api); break; | ||
default: token[key] = meta[key]; break; | ||
|
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.
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.
This was annoying me sometimes with collab, good that you handled it here