Skip to content

Commit aa70eac

Browse files
committed
report instruction_limit_reached for JS code
1 parent 14eab0f commit aa70eac

5 files changed

Lines changed: 52 additions & 18 deletions

File tree

‎v4-cokapi/Dockerfile‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# TODO: gradually peel off backends from here into their own separate
2+
# Docker images. right now this is for the Java and Ruby backends
3+
14
# to build:
25
# docker build -t="pgbovine/cokapi:v1" .
36
#
@@ -52,19 +55,6 @@ ADD backends/java/java_jail/cp/ /tmp/java_jail/cp
5255
# compile all Java files within cp/
5356
RUN cd /tmp/java_jail/cp && find . -name "*.java" -print | xargs javac -cp .:javax.json-1.0.jar:/usr/lib/jvm/java-7-openjdk-amd64/lib/tools.jar
5457

55-
# JS and Python backends
56-
RUN mkdir /tmp/javascript
57-
RUN mkdir /tmp/python
58-
59-
# IMPORTANT: make sure to run 'make deps' in backends/javascript first
60-
# to install the proper node modules inside of here via npm before
61-
# creating this Docker container, since it's a pain to install npm and
62-
# modules within the container. Also untar node-v6.0.0-linux-x64.tar.xz
63-
# (or the proper version of Node so that the proper binary is within the
64-
# directory already before copying into container)
65-
ADD backends/javascript /tmp/javascript
66-
ADD backends/python /tmp/python
67-
6858
COPY backends/java/run-java-backend.sh /tmp/
6959
RUN chmod a+x /tmp/run-java-backend.sh
7060

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# to build:
2+
# docker build -t="pgbovine/cokapi-js:v1" .
3+
#
4+
# to test:
5+
# docker run -t -i --rm --user=netuser --net=none --cap-drop all pgbovine/cokapi-js:v1 bash
6+
#
7+
# remember --rm or else stale old containers will be left around!
8+
# use "docker ps -a" to see all containers
9+
10+
# don't use 'latest' tag since that might change
11+
FROM ubuntu:14.04.1
12+
MAINTAINER Philip Guo <philip@pgbovine.net>
13+
14+
RUN useradd netuser
15+
16+
# if apt-get doesn't work, then follow these instructions:
17+
# http://stackoverflow.com/questions/24991136/docker-build-could-not-resolve-archive-ubuntu-com-apt-get-fails-to-install-a
18+
# Uncomment the following line in /etc/default/docker DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
19+
# Restart the Docker service sudo service docker restart
20+
RUN apt-get update && apt-get install -y \
21+
python
22+
23+
RUN mkdir /tmp/javascript
24+
25+
# IMPORTANT: make sure to run 'make deps' in backends/javascript first
26+
# to install the proper node modules inside of here via npm before
27+
# creating this Docker container, since it's a pain to install npm and
28+
# modules within the container. Also untar node-v6.0.0-linux-x64.tar.xz
29+
# (or the proper version of Node so that the proper binary is within the
30+
# directory already before copying into container)
31+
ADD . /tmp/javascript

‎v4-cokapi/backends/javascript/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ diffall:
2424
deps:
2525
npm install eval@0.1.0 underscore minimist source-map typescript@1.4
2626
tar -xvf node-v6.0.0-linux-x64.tar.xz
27+
28+
docker:
29+
docker build -t="pgbovine/cokapi-js:v1" .
30+
31+
dockerbash:
32+
docker run -t -i --rm --user=netuser --net=none --cap-drop all pgbovine/cokapi-js:v1 bash

‎v4-cokapi/backends/javascript/jslogger.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ function listener(event, execState, eventData, data) {
987987
//while (!process.stdout.flush()); // flush before finalize; for some weird reason it works, ergh
988988

989989
finalize();
990-
process.exit(0 /* don't use an error exit code so that we don't trigger error handlers later on */);
990+
process.exit(42 /* use a weird error code to indicate instruction_limit_reached so cokapi.js can parse it */);
991991
} else {
992992
assert(stepType !== undefined);
993993
execState.prepareStep(stepType); // set debugger to stop at next step

‎v4-cokapi/cokapi.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,15 @@ function postExecHandler(res, useJSONP, err, stdout, stderr) {
8181
res.send(JSON.stringify(errTrace));
8282
}
8383
} else {
84-
errTrace = {code: '', trace: [{'event': 'uncaught_exception',
85-
'exception_msg': "Unknown error. Report a bug to philip@pgbovine.net by clicking on the\n'Generate permanent link' button at the bottom and including a URL in your email."}]};
84+
if (err.code === 42) {
85+
// special error code for instruction_limit_reached in jslogger.js
86+
errTrace = {code: '', trace: [{'event': 'uncaught_exception',
87+
'exception_msg': 'Stopped after running 1000 steps. Please shorten your code,\nsince Python Tutor is not designed to handle long-running code.'}]};
88+
} else {
89+
errTrace = {code: '', trace: [{'event': 'uncaught_exception',
90+
'exception_msg': "Unknown error. Report a bug to philip@pgbovine.net by clicking on the\n'Generate permanent link' button at the bottom and including a URL in your email."}]};
91+
}
92+
8693
if (useJSONP) {
8794
res.jsonp(errTrace /* return an actual object, not a string */);
8895
} else {
@@ -97,7 +104,7 @@ function postExecHandler(res, useJSONP, err, stdout, stderr) {
97104
res.jsonp(stdoutParsed /* return an actual object, not a string */);
98105
} catch(e) {
99106
errTrace = {code: '', trace: [{'event': 'uncaught_exception',
100-
'exception_msg': "Unknown error, possibly because your code ran for too long. Try to shorten your code,\nand if that doesn't work then report a bug to philip@pgbovine.net by clicking on the\n'Generate permanent link' button at the bottom and including a URL in your email."}]};
107+
'exception_msg': "Unknown error. Report a bug to philip@pgbovine.net by clicking on the\n'Generate permanent link' button at the bottom and including a URL in your email."}]};
101108
res.jsonp(errTrace /* return an actual object, not a string */);
102109
}
103110
} else {
@@ -135,7 +142,7 @@ function exec_js_handler(useJSONP /* use bind first */, isTypescript /* use bind
135142
if (USE_DOCKER_SANDBOX) {
136143
// this needs to match the docker setup in Dockerfile
137144
exeFile = '/usr/bin/docker'; // absolute path to docker executable
138-
args.push('run', '-m', MEM_LIMIT, '--rm', '--user=netuser', '--net=none', '--cap-drop', 'all', 'pgbovine/cokapi:v1',
145+
args.push('run', '-m', MEM_LIMIT, '--rm', '--user=netuser', '--net=none', '--cap-drop', 'all', 'pgbovine/cokapi-js:v1',
139146
//'node', // built-in Node.js version
140147
'/tmp/javascript/node-v6.0.0-linux-x64/bin/node', // custom Node.js version
141148
'--expose-debug-as=Debug',

0 commit comments

Comments
 (0)